我尝试合并两个640像素宽的位图,但结果总是一个1024宽的位图。我如何让android创建一个1280宽的位图?
我使用下面的代码来缩放我的位图:
public static Bitmap scaleWidthImage(Bitmap image, int destWidth) {
int origWidth = image.getWidth();
int origHeight = image.getHeight();
int destHeight;
if (origWidth > destWidth) {
destHeight = origHeight / (origWidth / destWidth);
} else {
destHeight = origHeight * (destWidth / origWidth);
}
image = Bitmap.createScaledBitmap(image, destWidth, destHeight, false);
return image;
}
这段代码用于将两个位图合并为一个
fun mergeBitmap(fr: Bitmap, sc: Bitmap): Bitmap? {
val comboBitmap: Bitmap
val width: Int = fr.width + sc.width
val height: Int = fr.height
comboBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val comboImage = Canvas(comboBitmap)
comboImage.drawBitmap(fr, 0f, 0f, null)
comboImage.drawBitmap(sc, fr.width.toFloat(), 0f, null)
return comboBitmap
}
当两个位图的宽度都小于1024像素时,合并后的位图具有所需的宽度,但当两者之和大于1024像素时,合并后的位图就不具有所需的宽度。
1条答案
按热度按时间cbjzeqam1#
我试过下面两张图片:
640x640图像:
640x800图像:
我创建了这个方法来将两个位图合并为一个:
结果1280x800: