image - Android: Streched Bitmap after Matrix Rotation -
im trying rotate jpeg data array converting bitmap , rotating matrix. working fine problem appear when im trying rotate 16:9 image(with 4:3 think happen too, can appreciate well). cause matrix rotate image dont resize it, bitmap looking streched width or height depending of orientation im sending dataarray.
protected bitmap doinbackground(void... params) { // decode image in background. bitmap bitmap = camerautil.downsample(mdata, mdownsamplefactor); matrix m = new matrix(); log.i(tag, "bitmap=" + bitmap.getwidth() + "x" + bitmap.getheight()); if ((morientation != 0 || mmirror) && (bitmap != null)) { if (mmirror) { m.setscale(1f, -1f); } m.postrotate(morientation); return bitmap.createbitmap(bitmap,0,0,bitmap.getwidth(),bitmap.getheight(),m,false); } return bitmap; } public static bitmap downsample(final byte[] data, int downsamplefactor) { final bitmapfactory.options opts = new bitmapfactory.options(); // downsample image opts.insamplesize = downsamplefactor; return bitmapfactory.decodebytearray(data, 0, data.length, opts); }
i tried resize image manually, convert array nv21 image , rotate array convert later bitmap , send it. giving me problems(so slow , totally green , pink(raimbows!)). tryed use pre,set , postrotate too, didnt give me differente between tests made.
thx in advance!
i found way fix it. problem inside crop method, use static measures create bitmap, change method addapt depending of aspect ratio.
if (bmp.getwidth() != radius || bmp.getheight() != radius) { //depending of height , width aspect ratio scale image before crop if (bmp.getheight() > bmp.getwidth()) { maspectratio = (float) bmp.getheight() / (float) bmp.getwidth(); sbmp = bitmap.createscaledbitmap(bmp, radius, (int) (radius * maspectratio), false); } else { maspectratio = (float) bmp.getwidth() / (float) bmp.getheight(); sbmp = bitmap.createscaledbitmap(bmp, (int) (radius * maspectratio), radius, false); } } } else { sbmp = bmp; } //output bitmap have final scale of thumbnail, radius x radius bitmap output = bitmap.createbitmap(radius,radius, config.argb_8888); canvas canvas = new canvas(output); //.....draw canvas, etc etc
Comments
Post a Comment