calculate resized image size in rect

1 vote · 2 comments

just calcurate size

raw ·
copy
· download
/** use like below Point pt=calculateFitImage(baseImage,width,height,null); Bitmap resizedBitmap = Bitmap Bitmap.createScaledBitmap(baseImage, pt.x, pt.y, true); */ public static Point calculateFitImage(Bitmap baseImage,int width,int height,Point receiver){ if(receiver==null){ receiver=new Point(); } int dw=width; int dh=height; if(dw!=0 && dh!=0 ){ double waspect=(double)dw/baseImage.getWidth(); double haspect=(double)dh/baseImage.getHeight(); if(waspect>haspect){//fit h dw=(int) (baseImage.getWidth()*haspect); }else{ dh=(int)(baseImage.getHeight()*waspect); } Log.i("imageUtil","waspect="+waspect+" haspect="+haspect+" dw="+dw+" dh="+dh); } receiver.x=dw; receiver.y=dh; return receiver; }
Add a comment

2 Comments

I don't see how it works.

It just return the calculate size of image stretched in specified size.

Reply · July 29, 2009, 3:01 p.m.

thanks for response. I changed title and info.

Reply · July 29, 2009, 3:37 p.m.