image - Android: bitmap down scaling low quality -
i'm scaling down bitmaps , getting low quality results. tried bitmap#createscaledbitmap , canvas#drawbitmap method. setting filter parameter in first , filter flag in paint object of second have shown no visible difference.
i tried solutions founded in these questions:
bad image quality after resizing/scaling bitmap
quality problems when resizing image @ runtime
drawing scaled bitmaps on surfaceview -- no antialiasing
and others.
as said somewhere, filter flag in createscaledbitmap or in paint object enables bicubic interpolation algorithm. however, makes no difference. using gimp cubic, in fact bicubic, resulting image better android implementation.
api level here 19.
try this, may you.
public static bitmap scalecentercrop(bitmap source, int newheight, int newwidth) { int sourcewidth = source.getwidth(); int sourceheight = source.getheight(); float xscale = (float) newwidth / sourcewidth; float yscale = (float) newheight / sourceheight; float scale = math.max(xscale, yscale); //get resulting size after scaling float scaledwidth = scale * sourcewidth; float scaledheight = scale * sourceheight; //figure out should translate float dx = (newwidth - scaledwidth) / 2; float dy = (newheight - scaledheight) / 2; bitmap dest = bitmap.createbitmap(newwidth, newheight, source.getconfig()); canvas canvas = new canvas(dest); matrix matrix = new matrix(); matrix.postscale(scale, scale); matrix.posttranslate(dx, dy); canvas.drawbitmap(source, matrix, null); return dest; }
Comments
Post a Comment