本文介绍了如何在中间创建带有徽标的QR码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用android在QR码图像中间添加徽标图像吗?



我已经生成了QR码,但现在我需要的是在二维码的中间插入徽标图片。



有没有办法实现这个目标。



这是我的QR代码,带有Logo代码:



> private String LOG_TAG =" GenerateQRCode";

private Bitmap myLogo, bitmap,bitMerged;



public void onClick(查看v){



EditText qrInput =(EditText) findViewById(R.id.qrInput);

String qrInputText = qrInput.getText()。toString();

Log.v(LOG_TAG,qrInputText);

Point point = new Point();

// display.getSize(point);

int width = point.x;

int height = point.y;

int smallerDimension = width<身高? width:height;

smallerDimension = smallerDimension * 3/4;



//用二维码图像编码

QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText,null,Contents.Type.TEXT,BarcodeFormat.QR_CODE.toString(),smallerDimension);

try {

bitmap = qrCodeEncoder .encodeAsBitmap();



myLogo = BitmapFactory.decodeResource(getResources(),R.drawable.image);



bitMerged = mergeBitmaps(bitmap,myLogo);



ImageView myImage =(ImageView)findViewById(R.id.imageView1);



myImage.setImageBitmap(bitMerged);



} catch(WriterException e){

e。 printStackTrace();

}

}

公共静态位图mergeBitmaps(位图bmp1,位图bmp2){

位图bmOverlay = Bitmap.createBitmap(bmp1.getWidth(),bmp1.getHeight(),bmp1.getConfig() );

Canvas canvas = new Canvas(bmOverlay);

canvas.drawBitmap(bmp1,new Matrix(),null);

canvas .drawBitmap(bmp2,0,0,null);

返回bmOverlay;

}

}



我不知道有没有人可以指导我清除这个问题..



提前感谢帮助的心。

It is Possible to add logo image in the middle of QR code image using android?

I have generated the QR code but now what i need is need to insert the logo image in the middle of QR code.

Is there any way to achieve this.

Here is my QR code with Logo Generation code:

>private String LOG_TAG = "GenerateQRCode";
private Bitmap myLogo, bitmap, bitMerged;

public void onClick(View v) {

EditText qrInput = (EditText) findViewById(R.id.qrInput);
String qrInputText = qrInput.getText().toString();
Log.v(LOG_TAG, qrInputText);
Point point = new Point();
// display.getSize(point);
int width = point.x;
int height = point.y;
int smallerDimension = width < height ? width : height;
smallerDimension = smallerDimension * 3/4;

//Encode with a QR Code image
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText,null,Contents.Type.TEXT,BarcodeFormat.QR_CODE.toString(),smallerDimension);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();

myLogo = BitmapFactory.decodeResource(getResources(), R.drawable.image);

bitMerged = mergeBitmaps(bitmap, myLogo);

ImageView myImage = (ImageView) findViewById(R.id.imageView1);

myImage.setImageBitmap(bitMerged);

} catch (WriterException e) {
e.printStackTrace();
}
}
public static Bitmap mergeBitmaps(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, 0, 0, null);
return bmOverlay;
}
}

I don't have idea about that could someone please guide me to clear this issue..

Thanks in advance for the helping hearts.

推荐答案


setBitmap(Bitmap bitmap)



2。将徽标绘制到QR码位图上。


2. draw the logo onto the QR code bitmap.

public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint)


这篇关于如何在中间创建带有徽标的QR码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 14:40