This article will talk about the effect of image effects processing relief. As before, the pixel is processed, and the algorithm is universal.
Algorithm principle: Subtract the RGB value of the current pixel by the RGB value of the previous pixel, and add 127 as the RGB value of the current pixel point.
Cases:
Abc
The relief effect of the B point 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 the RGB values are between 0~255.
:
Original
[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 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 canvas) {
- Super.ondraw (canvas);
- //Get pixels
- Bitmap.getpixels (Oldpixels, 0, width, 0, 0, width, height);
- For (int i = 1;i < height*width; i++) {
- color = oldpixels[i-1];
- //Previous 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 > 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);
- }
- }
Android image processing (3) Emboss effect