Android image scaling and image rounded corner Processing

Source: Internet
Author: User

/** <Br/> * [Image Scaling] <br> <br/> * [function description] <br/> * @ Param bitmaporg <br/> * @ Param dstw <br/> * @ Param d...... <br/> * @ return <br/> */<br/> Public static bitmap resizeimage (Bitmap bitmaporg, int dstw, int d......) <br/>{</P> <p> bitmap resizedbitmap; <br/> int srcw = bitmaporg. getwidth (); <br/> int srch = bitmaporg. getheight (); </P> <p> // If the length and width are smaller than the generated target image, directly return the image <br/> If (srcw <= dstw & srch <= dsomething) <br/>{</P> <p> return bitmaporg; <br/>}< br/> // else if (srcw> dstw & srch <DTH) <br/> // {<br/> // resizedbitmap <br/> //} </P> <p> float scalewidth = (float) dstw)/srcw; <br/> float scaleheight = (float) d......)/srch; </P> <p> // create a matrix for the manipulation <br/> matrix = new matrix (); <br/> // resize the bitmap <br/> matrix. postscale (scalewidth, scaleheight); <br/> // If You Want to rotate the bitmap <br/> // matrix. postrotate (45); </P> <p> // recreate the new bitmap <br/> resizedbitmap = bitmap. createbitmap (bitmaporg, 0, 0, srcw, srch, <br/> matrix, true); <br/> bitmaporg. recycle (); <br/> // make a drawable from Bitmap to allow to set the bitmap <br/> // to the imageview, imagebutton or what ever <br/> return resizedbitmap; </P> <p >}</P> <p>/** <br/> * [Image rounded corner processing] <br> <br/> * [function description] <br/> * @ Param bitmap <br/> * @ Param roundpx <br/> * @ return <br/> */ <br/> Public static bitmap getrcb (Bitmap bitmap, float roundpx) // rcb means rounded corner bitmap <br/>{< br/> bitmap dstbmp = bitmap. createbitmap (bitmap. getwidth (), <br/> bitmap. getheight (), config. argb_8888); <br/> canvas = new canvas (dstbmp); </P> <p> final int color = 0xff0000242; <br/> final paint = new paint (); <br/> final rect = new rect (0, 0, bitmap. getwidth (), bitmap. getheight (); <br/> final rectf = new rectf (rect); <br/> paint. setantialias (true); <br/> canvas. drawargb (0, 0, 0, 0); <br/> paint. setcolor (color); <br/> canvas. drawroundrect (rectf, roundpx, roundpx, paint); <br/> paint. setxfermode (New porterduduxfermode (mode. src_in); <br/> canvas. drawbitmap (bitmap, rect, rect, paint); </P> <p> return dstbmp; <br/>}

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.