Zoom the picture by calculating the image zoom value
/** * Follow the path to get a break and compress the return bitmap used to display * * @param filePath * @return*/ Public StaticBitmap Getsmallbitmap (String FilePath,intWidthintheight) {Final Bitmapfactory.options Options=Newbitmapfactory.options (); Options.injustdecodebounds=true; Bitmapfactory.decodefile (FilePath, Options); //Calculate insamplesizeOptions.insamplesize =calculateinsamplesize (options, width, height); //Decode bitmap with Insamplesize setOptions.injustdecodebounds =false; returnbitmapfactory.decodefile (FilePath, Options); }
Calculate the zoom value of a picture
/** * Calculate the zoom value of the picture * * @param options * @param reqwidth * @param reqheight * @return*/ Public Static intcalculateinsamplesize (bitmapfactory.options Options,intReqwidth,intreqheight) { //Raw Height and width of imageFinalintHeight =Options.outheight; Finalintwidth =Options.outwidth; intInsamplesize =1; if(Height > Reqheight | | width >reqwidth) { //Calculate ratios of height and width to requested height and//widthFinalintHeightRatio = Math.Round ((float) Height/ (float) reqheight); FinalintWidthRatio = Math.Round ((float) Width/(float) reqwidth); //Choose the smallest ratio as insamplesize value, this would//Guarantee//a final image with both dimensions larger than or equal to the//requested height and width.Insamplesize = HeightRatio < WidthRatio?Heightratio:widthratio; } hclog.d ("Hcutil #calculateInSampleSize ="+insamplesize); returninsamplesize; }
Android Image Zoom