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. enter image description here enter image description here

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

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -