使用android可以在QR碼圖像的中間添加徽標圖像嗎?如何在中間創建帶有徽標的QR碼
我已經生成了QR碼,但現在我需要的是需要在QRcode中插入徽標圖像。
有什麼辦法可以達到這個目的。
這是我的QR碼生成代碼:
位圖myLogo = BitmapFactory.decodeResource(getResources(),R.drawable.image); 公共無效的onClick(視圖v){
EditText qrInput = (EditText) findViewById(R.id.qrInput);
String qrInputText = qrInput.getText().toString();
Log.v(LOG_TAG, qrInputText);
//Find screen size
WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
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 bitmap = qrCodeEncoder.encodeAsBitmap();
ImageView myImage = (ImageView) findViewById(R.id.imageView1);
myImage.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
}
我沒有想過這可能有人請指引我前進一步的想法。
在此先感謝幫助的心。
我這是怎麼實現的:
Bitmap myLogo = BitmapFactory.decodeResource(getResources(), R.drawable.image);
public void onClick(View v) {
// switch (v.getId()) {
// case R.id.button1:
EditText qrInput = (EditText) findViewById(R.id.qrInput);
String qrInputText = qrInput.getText().toString();
Log.v(LOG_TAG, qrInputText);
//Find screen size
WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
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 bitmap = qrCodeEncoder.encodeAsBitmap();
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;
}
ImageView myImage = (ImageView) findViewById(R.id.imageView1);
myImage.setImageBitmap(mergeBitmaps);
} catch (WriterException e) {
e.printStackTrace();
}
我已經更新了答案。看看 –
你可以幫助AppDev。我添加了logo.but,它增加了左上角。你可以安排它在中心 – harikrishnan
請檢查我的答案在http://stackoverflow.com/questions/13247701/how-to-add-a-logo-to-qr-code-in-android/43197496#43197496,I已經解決了:) –