Relief effect Function

Source: Internet
Author: User

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
    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, 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 ){
    30. Super. ondraw (canvas );
    31. // Retrieve pixels
    32. Bitmap. getpixels (oldpixels, 0, width, 0, 0, width, height );
    33. For (INT I = 1; I
    34. Color = oldpixels [I-1];
    35. // The first 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 & gt; 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. }

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.