android-截图

截图

       if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
            val b: Bitmap = Bitmap.createBitmap(
                resources.displayMetrics.widthPixels,
                resources.displayMetrics.heightPixels,
                Bitmap.Config.ARGB_8888
            )
            PixelCopy.request(
                window,
                Rect(
                    0,
                    0,
                    resources.displayMetrics.widthPixels,
                    resources.displayMetrics.heightPixels
                ), b,
                {
                    if (it == PixelCopy.SUCCESS) {
                        viewBinding.contentImage.setImageBitmap(b)
                    }
                },
                Handler(mainLooper)
            )
        } else {
            viewBinding.root.isDrawingCacheEnabled = true
            viewBinding.root.buildDrawingCache(true)
            val a = viewBinding.root.drawingCache
            val resource = Bitmap.createBitmap(a, 0, 0, a.width, a.height)
            viewBinding.root.isDrawingCacheEnabled = false
            viewBinding.root.destroyDrawingCache()
            viewBinding.contentImage.setImageBitmap(resource)
        }



你可能感兴趣的:(android,android,studio,kotlin)