如何调整我的代码以获取所需的屏幕截图,同时裁剪顶部和底部?
How can I adapt my code to take the desired screenshot, cropping both top and bottom?
我有以下 Kotlin
代码,它截取了显示区域的屏幕截图:
fun screenShot() {
val bitmap = Bitmap.createBitmap(wholeScreen.width,wholeScreen.height-gameDimensions.bottomNavigationViewHeight, Bitmap.Config.ARGB_8888)
val croppedBitmap = Bitmap.createBitmap(bitmap, 0, gameDimensions.verticalInc.toInt(), bitmap.width, (bitmap.height - gameDimensions.verticalInc).toInt())
val canvas = Canvas(croppedBitmap)
wholeScreen.draw(canvas)
val out = ByteArrayOutputStream()
croppedBitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
val screenShot = ColourBoardScreenShot(BitmapDrawable(theUi.resources, croppedBitmap))
bundle.putParcelable ("screenshot", screenShot)
}
原版画面:
当前截图:
想要的截图:
有点尴尬,但我不知道怎么截图蓝色的!
您需要通过Add
将canvas位置从0,0移动到新位置
canvas.translate(0, -gameDimensions.verticalInc.toInt())
在 wholeScreen.draw(canvas)
之前
我有以下 Kotlin
代码,它截取了显示区域的屏幕截图:
fun screenShot() {
val bitmap = Bitmap.createBitmap(wholeScreen.width,wholeScreen.height-gameDimensions.bottomNavigationViewHeight, Bitmap.Config.ARGB_8888)
val croppedBitmap = Bitmap.createBitmap(bitmap, 0, gameDimensions.verticalInc.toInt(), bitmap.width, (bitmap.height - gameDimensions.verticalInc).toInt())
val canvas = Canvas(croppedBitmap)
wholeScreen.draw(canvas)
val out = ByteArrayOutputStream()
croppedBitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
val screenShot = ColourBoardScreenShot(BitmapDrawable(theUi.resources, croppedBitmap))
bundle.putParcelable ("screenshot", screenShot)
}
原版画面:
当前截图:
想要的截图:
有点尴尬,但我不知道怎么截图蓝色的!
您需要通过Add
将canvas位置从0,0移动到新位置canvas.translate(0, -gameDimensions.verticalInc.toInt())
在 wholeScreen.draw(canvas)