Android Development Zoom to a specified scale size

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.