android - How to resize bitmap image programmatically with out missing the data -
i developing android application in want set banner image on top of screen come server, need resize dynamically according device size programmatically.
try this,
int iwidth=bmp.getwidth(); int iheight=bmp.getheight();
display display = getwindowmanager().getdefaultdisplay(); displaymetrics dm = new displaymetrics(); display.getmetrics(dm); int dwidth=dm.widthpixels; int dheight=dm.heightpixels; float swidth=((float) dwidth)/iwidth; float sheight=((float) dheight)/iheight; if(swidth>sheight) swidth=sheight; else sheight=swidth; matrix matrix=new matrix(); matrix.postscale(swidth,sheight); newimage=bitmap.createbitmap(bmp, 0, 0, iwidth, iheight, matrix, true); imageview.setimagebitmap(newimage);
Comments
Post a Comment