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