Android Adjust Picture Tool class

Source: Internet
Author: User

Package Com.base.changeimage;import Android.graphics.bitmap;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.colormatrix;import Android.graphics.colormatrixcolorfilter;import android.graphics.paint;/** * Adjust Picture tool class */public class Imagehelper {/** * Adjust image * @param BM image * @param hue color Adjust * @param stauration saturation * @param lum Brightness * @return */public static Bitmap Handleimageeffect (Bitmap BM , float hue, float stauration, float Lum) {Bitmap bmp = Bitmap.createbitmap (Bm.getwidth (), Bm.getheight (), Bitmap.        config.argb_8888);        Canvas canvas = new canvas (BMP);        Paint paint = new paint (Paint.anti_alias_flag);        ColorMatrix Huematrix = new ColorMatrix ();        Huematrix.setrotate (0, Hue);        Huematrix.setrotate (1, Hue);        Huematrix.setrotate (2, Hue);        ColorMatrix Saturationmatrix = new ColorMatrix ();        Saturationmatrix.setsaturation (stauration); ColorMatrix Lummatrix = new ColormatRix ();        Lummatrix.setscale (Lum, Lum, Lum, 1);        ColorMatrix Imagematrix = new ColorMatrix ();        Imagematrix.postconcat (Huematrix);        Imagematrix.postconcat (Saturationmatrix);        Imagematrix.postconcat (Lummatrix);        Paint.setcolorfilter (New Colormatrixcolorfilter (Imagematrix));        Canvas.drawbitmap (BM, 0, 0, paint);    return BMP; }/** * Negative effect * @param BM * @return */public static Bitmap handleimagenegative (Bitmap bm) {I        NT width = bm.getwidth ();        int height = bm.getheight ();        int color;        int R, G, B, A;        Bitmap bmp = Bitmap.createbitmap (width, height, Bitmap.Config.ARGB_8888);        int[] Oldpx = new int[width * height];        int[] newpx = new int[width * height];        Bm.getpixels (oldpx, 0, width, 0, 0, width, height);            for (int i = 0; I < width * height; i++) {color = Oldpx[i];            R = color.red (Color);      g = Color.green (Color);      b = Color.Blue (Color);            A = Color.alpha (Color);            R = 255-r;            g = 255-g;            b = 255-b;            if (R > 255) {r = 255;            } else if (R < 0) {r = 0;            } if (g > 255) {g = 255;            } else if (G < 0) {g = 0;            } if (b > 255) {b = 255;            } else if (b < 0) {b = 0;        } Newpx[i] = Color.argb (A, R, G, b);        } bmp.setpixels (NEWPX, 0, width, 0, 0, width, height);    return BMP;        }/** * Black and white effects * @param BM * @return */public static Bitmap Handleimagepixelsoldphoto (Bitmap BM) {        Bitmap bmp = Bitmap.createbitmap (Bm.getwidth (), Bm.getheight (), Bitmap.Config.ARGB_8888);        int width = bm.getwidth ();        int height = bm.getheight ();        int color = 0;   int R, G, B, A, R1, G1, B1;     int[] Oldpx = new int[width * height];        int[] newpx = new int[width * height];        Bm.getpixels (oldpx, 0, Bm.getwidth (), 0, 0, width, height);            for (int i = 0; I < width * height; i++) {color = Oldpx[i];            A = Color.alpha (Color);            R = color.red (Color);            g = Color.green (Color);            b = Color.Blue (Color);            R1 = (int) (0.393 * r + 0.769 * g + 0.189 * b);            G1 = (int) (0.349 * r + 0.686 * g + 0.168 * b);            B1 = (int) (0.272 * r + 0.534 * g + 0.131 * b);            if (R1 > 255) {r1 = 255;            } if (G1 > 255) {g1 = 255;            } if (B1 > 255) {b1 = 255;        } Newpx[i] = Color.argb (A, R1, G1, B1);        } bmp.setpixels (NEWPX, 0, width, 0, 0, width, height);    return BMP; }/** * Embossed effect * @param BM * @return */public static Bitmap HandleimagepixelsrelieF (Bitmap BM) {Bitmap bmp = Bitmap.createbitmap (Bm.getwidth (), Bm.getheight (), Bitmap.Config.ARGB_88        88);        int width = bm.getwidth ();        int height = bm.getheight ();        int color = 0, Colorbefore = 0;        int A, R, G, B;        int R1, G1, B1;        int[] Oldpx = new int[width * height];        int[] newpx = new int[width * height];        Bm.getpixels (oldpx, 0, Bm.getwidth (), 0, 0, width, height);            for (int i = 1; i < width * height; i++) {colorbefore = oldpx[i-1];            A = Color.alpha (Colorbefore);            R = color.red (Colorbefore);            g = Color.green (Colorbefore);            b = Color.Blue (Colorbefore);            color = Oldpx[i];            R1 = color.red (Color);            G1 = Color.green (Color);            B1 = Color.Blue (Color);            R = (r-r1 + 127);            G = (g-g1 + 127);            B = (b-b1 + 127);            if (R > 255) {r = 255; } if (g > 255)            {g = 255;            } if (b > 255) {b = 255;        } Newpx[i] = Color.argb (A, R, G, b);        } bmp.setpixels (NEWPX, 0, width, 0, 0, width, height);    return BMP; }}

  

Android Adjust Picture Tool class

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.