这是一个技巧,实际上你的 QR 码生成器(如果你使用 zxing)返回一个位图值,所以你可以合并你的二维码位图和你的标志位图,这是一个示例:
首先,您必须有 void 来合并两个位图并调整徽标大小,以便可以将其放置在 QR 码的中心
public Bitmap mergeBitmaps(Bitmap logo, Bitmap qrcode) {
Bitmap combined = Bitmap.createBitmap(qrcode.getWidth(), qrcode.getHeight(), qrcode.getConfig());
Canvas canvas = new Canvas(combined);
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
canvas.drawBitmap(qrcode, new Matrix(), null);
Bitmap resizeLogo = Bitmap.createScaledBitmap(logo, canvasWidth / 5, canvasHeight / 5, true);
int centreX = (canvasWidth - resizeLogo.getWidth()) /2;
int centreY = (canvasHeight - resizeLogo.getHeight()) / 2;
canvas.drawBitmap(resizeLogo, centreX, centreY, null);
return combined;
}
然后,您使用该空白来合并 QR 码位图和徽标位图,并将其推送到图像视图中
Bitmap yourLogo = BitmapFactory.decodeResource(getResources(), R.drawable.your_logo);
Bitmap merge = mergeBitmaps(yourLogo, qrcode_bitmap);
yourImageView.setImageBitmap(merge);