One is scaled through matrix matrices:
//use bitmap plus matrix to zoom Public StaticDrawable Resizeimage (Bitmap Bitmap,intWinth) {Bitmap bitmaporg=bitmap; intwidth =bitmaporg.getwidth (); intHeight =bitmaporg.getheight (); intNewwidth =W; intNewheight =h; floatScaleWidth = ((float) newwidth)/width; floatScaleHeight = ((float) newheight)/height; Matrix Matrix=NewMatrix (); Matrix.postscale (ScaleWidth, ScaleHeight); //If you want to rotate the Bitmap//Matrix.postrotate (45); Bitmap Resizedbitmap = Bitmap.createbitmap (bitmaporg, 0, 0, width, height, matrix,true); return Newbitmapdrawable (RESIZEDBITMAP); }
Another, by setting the insamplesize parameter of the bitmapfactory.options to zoom
//use Bitmapfactory.options's insamplesize parameter to zoom Public Staticdrawable resizeImage2 (String path,intWidthintheight) {bitmapfactory.options Options=Newbitmapfactory.options (); Options.injustdecodebounds=true;//do not load bitmap into memoryBitmapfactory.decodefile (path,options); intOutwidth =Options.outwidth; intOutheight =Options.outheight; Options.indither=false; Options.inpreferredconfig=Bitmap.Config.ARGB_8888; Options.insamplesize= 1; if(Outwidth! = 0 && Outheight! = 0 && Width! = 0 && Height! = 0) { intSamplesize= (outwidth/width+outheight/height)/2; LOG.D (Tag,"SampleSize =" +samplesize); Options.insamplesize=samplesize; } options.injustdecodebounds=false; return Newbitmapdrawable (Bitmapfactory.decodefile (path, options)); }
Android Development Zoom to a specified scale size