如何在安卓中合并位图?[已关闭]
2022-09-03 09:42:32
我已经想通了:
public static Bitmap mergeToPin(Bitmap back, Bitmap front) {
Bitmap result = Bitmap.createBitmap(back.getWidth(), back.getHeight(), back.getConfig());
Canvas canvas = new Canvas(result);
int widthBack = back.getWidth();
int widthFront = front.getWidth();
float move = (widthBack - widthFront) / 2;
canvas.drawBitmap(back, 0f, 0f, null);
canvas.drawBitmap(front, move, move, null);
return result;
}
前置图像具有相等的高度和宽度,并且该高度/宽度与后置图像的宽度匹配(或缩放 - 我已将其大小调整为原始引脚宽度的90%)的技巧。
无论你是放了圆圈还是方形的图钉,只要图像的位置(圆形或正方形)具有相等的宽度和高度就没关系。当然,如果您希望将其添加到带圆圈的引脚:)
请尝试此功能。
private Bitmap createSingleImageFromMultipleImages(Bitmap firstImage, Bitmap secondImage){
Bitmap result = Bitmap.createBitmap(firstImage.getWidth(), firstImage.getHeight(), firstImage.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(firstImage, 0f, 0f, null);
canvas.drawBitmap(secondImage, 10, 10, null);
return result;
}
希望这有帮助。