Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.graphics.Bitmap
- import android.graphics.Canvas
- import android.graphics.Point
- import com.tencent.smtt.sdk.WebView
- /**
- * Created by yangjw on 2019/3/14.
- */
- fun WebView?.getSize(): Point? {
- if (this == null) {
- return null
- }
- return Point(computeHorizontalScrollRange(), computeVerticalScrollRange())
- }
- fun WebView?.getScreenShot(startX: Int, startY: Int, endX: Int, endY: Int): Bitmap? {
- if (this == null || startX < 0 || startY < 0 || endX < 0 || endY < 0) {
- return null
- }
- val size = getSize() ?: return null
- val wholeWidth = size.x
- val wholeHeight = size.y
- val wholePageBitmap = Bitmap.createBitmap(wholeWidth, wholeHeight, Bitmap.Config.ARGB_8888)
- val canvas = Canvas(wholePageBitmap)
- canvas.scale(wholeWidth.toFloat() / contentWidth, wholeHeight.toFloat() / contentHeight)
- x5WebViewExtension.snapshotWholePage(canvas, false, false)
- if (startX == 0 && startY == 0 && endX == wholeWidth && endY == wholeHeight) {
- return wholePageBitmap
- }
- return Bitmap.createBitmap(wholePageBitmap, startX, startY, endX - startX, endY - startY)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement