Android images and scaling down

Source: Internet
Author: User

Android images and scaling down

/*** Scale down the original proportion of the image file and make it not exceed the maximum width and height * @ param path: Image File * @ param requestW: max width after scaling * @ param requestH: max height after scaling * @ return thumbnail image object */public static Bitmap getThumbnailByReq (String path, int requestW, int requestH) {BitmapFactory. options options = new Options (); // only the source image size information is parsed. Therefore, only the source image boundary information is loaded into the memory, rather than the complete source image, saving the memory options. inJustDecodeBounds = true; BitmapFactory. decodeFile (path, options); int outW = options. outWidth; // source Image Width Int outH = options. outHeight; // source Image Height // set the scaling factor if (outW> requestW | outH> requestH) {int radioW = Math. round (float) outW/requestW); int radioH = Math. round (float) outH/requestH); options. inSampleSize = radioW> radioH? RadioW: radioH;} else {options. inSampleSize = 1;} // You Need to parse the correct image object. Therefore, add the scaled image to the memory options. inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory. decodeFile (path, options); return bitmap ;}

Related Article

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.