android - Resize image without aspect ratio -
i want resize bitmap image 512px,512px. use below code ,but when image resized bad , aspect ratio affected. how can resize image without aspect ratio?2nd image resized pc 512px.

public bitmap getresizedbitmap(bitmap bm, int newheight, int newwidth) { int width = bm.getwidth(); int height = bm.getheight(); float scalewidth = ((float) newwidth) / width; float scaleheight = ((float) newheight) / height; matrix matrix = new matrix(); matrix.postscale(scalewidth, scaleheight); bitmap resizedbitmap = bitmap.createbitmap(bm, 0, 0, width, height, matrix, false); return resizedbitmap; }
you can resize bitmap using this.
bitmap yourbitmap; bitmap resized = bitmap.createscaledbitmap(yourbitmap, newwidth, newheight, true); or:
resized = bitmap.createscaledbitmap(yourbitmap,(int)(yourbitmap.getwidth()*0.8), (int)(yourbitmap.getheight()*0.8), true);
Comments
Post a Comment