"Turn" four, Android image effect processing of the negative effects

Source: Internet
Author: User

This article will deal with the effect of film effects. As before, the pixel is processed, and the algorithm is universal.

Algorithm principle: The RGB value of the current pixel points and the difference of 255 respectively as the current point of the RGB value.

Cases:

Abc

To find the negative effect of B point:

B.R = 255-B.R;

B.G = 255-B.G;

b.b = 255-b.b;

Original:

Code:

 PackageCom.color;ImportAndroid.content.Context;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Color;ImportAndroid.graphics.Paint;ImportAndroid.util.AttributeSet;ImportAndroid.widget.ImageView; Public classColorviewextendsImageView {PrivatePaint Mypaint =NULL; PrivateBitmap Bitmap =NULL; Private intWidth,height; Private int[] oldpixels; Private int[] newpixels; Private intColor,color2; Private intPIXELSR,PIXELSG,PIXELSB,PIXELSA,PIXELSR2,PIXELSG2,PIXELSB2;  PublicColorview (Context context, AttributeSet attrs) {Super(context, attrs); Bitmap=Bitmapfactory.decoderesource (Context.getresources (), R.DRAWABLE.WW); Width=bitmap.getwidth (); Height=bitmap.getheight (); Oldpixels=New int[width*height]; Newpixels=New int[width*height];    Invalidate (); } @Overrideprotected voidOnDraw (canvas canvas) {Super. OnDraw (canvas); //Get PixelBitmap.getpixels (oldpixels, 0, width, 0, 0, width, height);  for(inti = 1;i < height*width; i++) {color=Oldpixels[i]; //Get RGB ComponentsPixelsa =Color.alpha (Color); PIXELSR=color.red (Color); PIXELSG=Color.green (Color); PIXELSB=Color.Blue (Color); //ConversionPIXELSR = (255-PIXELSR); PIXELSG= (255-PIXELSG); PIXELSB= (255-pixelsb); //is less than or equal to 255 greater than or equal to 0                if(PIXELSR > 255) {PIXELSR= 255; }                Else if(PIXELSR < 0) {PIXELSR= 0; }                if(Pixelsg > 255) {PIXELSG= 255; }                Else if(PIXELSG < 0) {PIXELSG= 0; }                if(Pixelsb > 255) {pixelsb= 255; }                Else if(PIXELSB < 0) {pixelsb= 0; }                //generate new pixels based on new RGBNewpixels[i] =Color.argb (Pixelsa, PIXELSR, PIXELSG, PIXELSB); }        //generate new pictures based on new pixelsBitmap.setpixels (newpixels, 0, width, 0, 0, width, height); Canvas.drawbitmap (Bitmap,0,0, Mypaint); }}

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.