This article describes the Relief Effect of image special effects. As before, pixels are processed, and algorithms are universal.
Algorithm principle: Use the RGB values of the previous pixel to subtract the RGB values of the current pixel, and add 127 to the RGB values of the current pixel respectively.
Example:
ABC
The relief effect of B is as follows:
B. R = C. R-B. R + 127;
B. G = C. G-B. G ++ 127;
B. B = c. B-B. B + 127;
Note that the RGB value ranges from 0 ~ In the range of 255.
:
Source image
[Java]View plaincopy
- Package com. color;
- Import Android. content. context;
- Import Android. Graphics. Bitmap;
- Import Android. Graphics. bitmapfactory;
- Import Android. Graphics. Canvas;
- Import Android. Graphics. color;
- Import Android. Graphics. paint;
- Import Android. util. attributeset;
- Import Android. widget. imageview;
- Public class colorview extends imageview {
- Private paint mypaint = NULL;
- Private Bitmap bitmap = NULL;
- Private int width, height;
- Private int [] oldpixels;
- Private int [] newpixels;
- Private int color, color2;
- Private int pixelsr, pixelsg, pixelsb, pixelsa, pixelsr2, pixelsg2, pixelsb2;
- Public colorview (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 ();
- }
- @ Override
- Protected void ondraw (canvas ){
- Super. ondraw (canvas );
- // Retrieve pixels
- Bitmap. getpixels (oldpixels, 0, width, 0, 0, width, height );
- For (INT I = 1; I
- Color = oldpixels [I-1];
- // The first Pixel
- Pixelsr = color. Red (color );
- Pixelsg = color. Green (color );
- Pixelsb = color. Blue (color );
- // Current Pixel
- Color2 = oldpixels [I];
- Pixelsr2 = color. Red (color2 );
- Pixelsg2 = color. Green (color2 );
- Pixelsb2 = color. Blue (color2 );
- Pixelsr = (pixelsr-pixelsr2 + 127 );
- Pixelsg = (pixelsg-pixelsg2 + 127 );
- Pixelsb = (pixelsb-pixelsb2 + 127 );
- // Both are less than or equal to 255
- If (pixelsr> 255 ){
- Pixelsr = 255;
- }
- If (pixelsg & gt; 255 ){
- Pixelsg = 255;
- }
- If (pixelsb> 255 ){
- Pixelsb = 255;
- }
- Newpixels [I] = color. argb (pixelsa, pixelsr, pixelsg, pixelsb );
- }
- Bitmap. setpixels (newpixels, 0, width, 0, 0, width, height );
- Canvas. drawbitmap (bitmap, 0, 0, mypaint );
- }
- }