Android image processing (3) Emboss effect

Source: Internet
Author: User

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
    1. Package com.color;
    2. Import Android.content.Context;
    3. Import Android.graphics.Bitmap;
    4. Import Android.graphics.BitmapFactory;
    5. Import Android.graphics.Canvas;
    6. Import Android.graphics.Color;
    7. Import Android.graphics.Paint;
    8. Import Android.util.AttributeSet;
    9. Import Android.widget.ImageView;
    10. Public class Colorview extends ImageView {
    11. private Paint mypaint = null;
    12. private Bitmap Bitmap = null;
    13. private int width,height;
    14. private int[] oldpixels;
    15. private int[] newpixels;
    16. private int color,color2;
    17. private int pixelsr,pixelsg,pixelsb,pixelsa,pixelsr2,pixelsg2,pixelsb2;
    18. Public Colorview (context context, AttributeSet attrs)
    19. {
    20. Super (context, attrs);
    21. Bitmap = Bitmapfactory.decoderesource (Context.getresources (), R.DRAWABLE.WW);
    22. width = Bitmap.getwidth ();
    23. Height = bitmap.getheight ();
    24. Oldpixels = new int[width*height];
    25. Newpixels = new int[width*height];
    26. Invalidate ();
    27. }
    28. @Override
    29. protected void OnDraw (canvas canvas) {
    30. Super.ondraw (canvas);
    31. //Get pixels
    32. Bitmap.getpixels (Oldpixels, 0, width, 0, 0, width, height);
    33. For (int i = 1;i < height*width; i++) {
    34. color = oldpixels[i-1];
    35. //Previous pixel
    36. PIXELSR = Color.Red (Color);
    37. PIXELSG = Color.green (Color);
    38. PIXELSB = Color.Blue (Color);
    39. //Current pixel
    40. Color2 = Oldpixels[i];
    41. pixelsR2 = Color.Red (Color2);
    42. pixelsG2 = Color.green (Color2);
    43. pixelsB2 = Color.Blue (Color2);
    44. PIXELSR = (PIXELSR-PIXELSR2 + 127);
    45. PIXELSG = (PIXELSG-PIXELSG2 + 127);
    46. PIXELSB = (PIXELSB-PIXELSB2 + 127);
    47. //Both are less than or equal to 255
    48. if (PIXELSR > 255) {
    49. PIXELSR = 255;
    50. }
    51. if (pixelsg > 255) {
    52. PIXELSG = 255;
    53. }
    54. if (pixelsb > 255) {
    55. PIXELSB = 255;
    56. }
    57. Newpixels[i] = Color.argb (Pixelsa, PIXELSR, PIXELSG, PIXELSB);
    58. }
    59. Bitmap.setpixels (Newpixels, 0, width, 0, 0, width, height);
    60. Canvas.drawbitmap (Bitmap,0,0,mypaint);
    61. }
    62. }

Android image processing (3) Emboss effect

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.