bitmap - Android: Generated QR code using Zxing has margins (is not fit to the area) -
i'm using in app zxing library generating qr code. want generated qr code should fits width of screen (maybe small padding).
if set width of screen width size of qr code smaller qr code. @ screenshot (it's 320x240 resolution). want qr code fit black area. why qr code in red small?
how stretch black area?
my code:
display display = getwindowmanager().getdefaultdisplay(); point size = new point(); display.getsize(size); int width = size.x; bitmap bm = encodeasbitmap(mgeneratedurl, barcodeformat.qr_code, width, width); qrcodeimage.setimagebitmap(bm);
generating qr code:
private bitmap encodeasbitmap(string contents, barcodeformat format, int img_width, int img_height) throws writerexception { string contentstoencode = contents; if (contentstoencode == null) { return null; } map<encodehinttype, object> hints = null; string encoding = guessappropriateencoding(contentstoencode); if (encoding != null) { hints = new enummap<encodehinttype, object>(encodehinttype.class); //hints.put(encodehinttype.character_set, encoding); hints.put(encodehinttype.margin, 0); /* default = 4 */ } multiformatwriter writer = new multiformatwriter(); bitmatrix result; try { result = writer.encode(contentstoencode, format, img_width, img_height, hints); } catch (illegalargumentexception iae) { // unsupported format return null; } int width = result.getwidth(); int height = result.getheight(); int[] pixels = new int[width * height]; (int y = 0; y < height; y++) { int offset = y * width; (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? red : color.black; } } bitmap bitmap = bitmap.createbitmap(width, height, bitmap.config.argb_8888); bitmap.setpixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
i find problem!
this line:
string encoding = guessappropriateencoding(contentstoencode);
returns null
so doesn´t set
encodehinttype.margin.
remove codition , should ok.
//if (encoding != null) { hints = new enummap<encodehinttype, object>(encodehinttype.class); //hints.put(encodehinttype.character_set, encoding); hints.put(encodehinttype.margin, 0); /* default = 4 */ //}
Comments
Post a Comment