Android simple image processing

Source: Internet
Author: User
Tags image flip

Collect Image Processing code on the Internet for future use.

 

I. Image flip (get the image after 180 degrees of flip)

Matrix M = new matrix ();

M. setscale (-1, 1 );

Bitmap newbit = bitmap. createbitmap (bit, 0, 0, bit. getwidth (), bit. getheight (), M, true );

 

Ii. Zoom in and out images

Matrix M = new matrix ();

M. setscale (0.5f, 0.5f); // scale down to half. The zoom ratio is greater than one zoom in S.

Bitmap newbit = bitmap. createbitmap (bit, 0, 0, bit. getwidth (), bit. getheight (), M, true );

 

Iii. Reflection

// Method for obtaining images with reflections

Public static bitmap createreflectionimagewithorigin (Bitmap bitmap) {final int reflectiongap = 4; int width = bitmap. getwidth (); int Height = bitmap. getheight ();

Matrix 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 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 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 in paint. setxfermode (New porterduxfermode (mode. dst_in ));

// Draw a rectangle using the paint with our linear gradient canvas. drawrect (0, height, width, bitmapwithreflection. getheight () + reflectiongap, paint );

Return bitmapwithreflection ;}

Iv. rounded corner image s

// Obtain the rounded corner Image

Public static bitmap getroundedcornerbitmap (Bitmap bitmap, float roundpx ){

Bitmap output = bitmap. createbitmap (bitmap. getwidth (), bitmap. getheight (), config. argb_8888 );

Canvas 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 porterduxfermode (mode. src_in ));

Canvas. drawbitmap (bitmap, rect, rect, paint );

Return output ;}

 

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.