我想创建一个kotlin函数,负责获取2个Bitmaps,并返回一个与两个合并图像相对应的图像。
第一个是一个默认的白色圆角标记(emptyMarkerBitmap),有一个固定的宽度和高度,第二个是一个随机的图像,我想把它最小化,以填充叠加的第一个图像。
private fun createBitmapOverlay(emptyMarkerBitmap: Bitmap, categoryIconBitmap: Bitmap): Bitmap {
val cs: Bitmap
val width: Int = emptyMarkerBitmap.width
val height: Int = emptyMarkerBitmap.height
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val comboImage = Canvas(cs)
comboImage.drawBitmap(emptyMarkerBitmap, 0f, 0f, null)
comboImage.drawBitmap(categoryIconBitmap, emptyMarkerBitmap.width.toFloat(), 0f, null)
return cs
}
目前,我总是得到显示的第一个图像,这是白色的标记。我的第二张图片从来没有显示过。问题出在哪里?
试试这个
fun Bitmap.with(bmp: Bitmap): Bitmap {
// Create new bitmap based on the size and config of the old
val newBitmap: Bitmap = Bitmap.createBitmap(width, height, config)
// Instantiate a canvas and prepare it to paint to the new bitmap
val canvas = Canvas(newBitmap)
// Draw the old bitmap onto of the new white one
canvas.drawBitmap(bmp, 0f, 0f, null)
return newBitmap
}
emptyMarkerBitmap.with(categoryIconBitmap)