Android image processing functions

Source: Internet
Author: User
// Zoom in and out the public static bitmap zoombitmap (Bitmap bitmap, int W, int h) {int width = bitmap. getwidth (); int Height = bitmap. getheight (); matrix = new matrix (); float scalewidht = (float) W/width); float scaleheight = (float) h/height); matrix. postscale (scalewidht, scaleheight); bitmap newbmp = bitmap. createbitmap (bitmap, 0, 0, width, height, matrix, true); Return newbmp;} // converts drawable to bitmappub LIC static bitmap drawabletobitmap (drawable) {int width = drawable. getintrinsicwidth (); int Height = drawable. getintrinsicheight (); Bitmap bitmap = bitmap. createbitmap (width, height, drawable. getopacity ()! = Pixelformat. opaque? Bitmap. config. argb_8888: bitmap. config. rgb_565); canvas = new canvas (Bitmap); drawable. setbounds (0, 0, width, height); drawable. draw (canvas); Return bitmap;} // public static bitmap getroundedcornerbitmap (Bitmap bitmap, float roundpx) {bitmap output = bitmap. createbitmap (bitmap. getwidth (), bitmap. getheight (), config. argb_8888); canvas = new canvas (output); Final int color = 0xff0000242; Final paint = new paint (); Final rect = new rect (0, 0, bitmap. getwidth (), bitmap. getheight (); Final rectf = new rectf (rect); paint. setantialias (true); canvas. drawargb (0, 0, 0, 0); paint. setcolor (color); canvas. drawroundrect (rectf, roundpx, roundpx, paint); paint. setxfermode (New porterduduxfermode (mode. src_in); canvas. drawbitmap (bitmap, rect, rect, paint); Return output;} // obtain the image method with reflection public static bitmap createreflectionimagewithorigin (Bitmap bitmap) {final int reflectiongap = 4; int width = bitmap. getwidth (); int Height = bitmap. getheight (); matrix = new matrix (); matrix. prescale (1,-1); bitmap reflectionimage = bitmap. createbitmap (bitmap, 0, height/2, width, height/2, matrix, false); bitmap bitmapwithreflection = bitmap. createbitmap (width, (height + height/2), config. argb_8888); canvas = new canvas (bitmapwithreflection); canvas. drawbitmap (bitmap, 0, 0, null); paint deafalutpaint = new paint (); canvas. drawrect (0, height, width, height + reflectiongap, deafalutpaint); canvas. drawbitmap (reflectionimage, 0, height + reflectiongap, null); paint = new paint (); lineargradient shader = new lineargradient (0, bitmap. getheight (), 0, bitmapwithreflection. getheight () + reflectiongap, 0x70ffffff, 0x00ffffff, tilemode. clamp); paint. setshader (shader); // set the transfer mode to be Porter Duff and destination inpaint. setxfermode (New porterduduxfermode (mode. dst_in); // draw a rectangle using the paint with our linear gradientcanvas. drawrect (0, height, width, bitmapwithreflection. getheight () + reflectiongap, paint); Return bitmapwithreflection ;}

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.