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 ;}