Image overlay for Android image effects processing

Source: Internet
Author: User

This article will talk about the image overlay effect processed by picture effects. The same as the front face is the pixel processing, you can refer to the previous Android image processing series seven-picture graffiti, watermark-image overlay and Android image processing series six-to the picture to add a border (bottom)-image Overlay Two articles, this article is a little different from before. The superposition principle is that the pixels of two pictures are superimposed by transparency, and no color filtering is done. Overlay images can be in JPG format, in front of the same, it is best to enlarge the assets directory. See below:

+ =

Code:

[Java]View PlainCopy
  1. /**
  2. * Image Effect Overlay
  3. * @param bmp limits the size of the bitmap
  4. * @return
  5. */
  6. Private Bitmap Overlay (Bitmap BMP)
  7. {
  8. Long start = System.currenttimemillis ();
  9. int width = bmp.getwidth ();
  10. int height = bmp.getheight ();
  11. Bitmap Bitmap = bitmap.createbitmap (width, height, Bitmap.Config.RGB_565);
  12. //Zoom in on a border picture
  13. Bitmap overlay = Bitmapfactory.decoderesource (Mcontext.getresources (), r.drawable.rainbow_overlay);
  14. int w = overlay.getwidth ();
  15. int h = overlay.getheight ();
  16. float ScaleX = width * 1F/W;
  17. float ScaleY = height * 1f/h;
  18. Matrix matrix = new Matrix ();
  19. Matrix.postscale (ScaleX, ScaleY);
  20. Bitmap overlaycopy = Bitmap.createbitmap (overlay, 0, 0, W, h, Matrix, true);
  21. int pixcolor = 0;
  22. int laycolor = 0;
  23. int pixr = 0;
  24. int pixg = 0;
  25. int pixb = 0;
  26. int pixA = 0;
  27. int newr = 0;
  28. int NEWG = 0;
  29. int newb = 0;
  30. int Newa = 0;
  31. int Layr = 0;
  32. int layg = 0;
  33. int layb = 0;
  34. int layA = 0;
  35. final Float alpha = 0.5F;
  36. int[] srcpixels = new int[width * height];
  37. int[] laypixels = new int[width * height];
  38. Bmp.getpixels (Srcpixels, 0, width, 0, 0, width, height);
  39. Overlaycopy.getpixels (Laypixels, 0, width, 0, 0, width, height);
  40. int pos = 0;
  41. For (int i = 0; i < height; i++)
  42. {
  43. For (int k = 0; k < width; k++)
  44. {
  45. pos = i * width + k;
  46. Pixcolor = Srcpixels[pos];
  47. Laycolor = Laypixels[pos];
  48. PIXR = Color.Red (Pixcolor);
  49. Pixg = Color.green (Pixcolor);
  50. PIXB = Color.Blue (Pixcolor);
  51. PixA = Color.alpha (Pixcolor);
  52. Layr = Color.Red (Laycolor);
  53. LAYG = Color.green (Laycolor);
  54. Layb = Color.Blue (Laycolor);
  55. LayA = Color.alpha (Laycolor);
  56. NEWR = (int) (PIXR * alpha + Layr * (1-alpha));
  57. NEWG = (int) (PIXG * alpha + LAYG * (1-alpha));
  58. Newb = (int) (PIXB * alpha + Layb * (1-alpha));
  59. LayA = (int) (PixA * alpha + LayA * (1-alpha));
  60. NEWR = Math.min (255, Math.max (0, NEWR));
  61. NEWG = Math.min (255, Math.max (0, NEWG));
  62. Newb = Math.min (255, Math.max (0, newb));
  63. Newa = Math.min (255, Math.max (0, LayA));
  64. Srcpixels[pos] = Color.argb (Newa, NEWR, NEWG, newb);
  65. }
  66. }
  67. Bitmap.setpixels (Srcpixels, 0, width, 0, 0, width, height);
  68. Long end = System.currenttimemillis ();
  69. LOG.D ("may", "Overlayameliorate used time=" + (End-start));
  70. return bitmap;
  71. }


Overlay picture of the border is better, but also to control the size of the superimposed picture. The value of alpha variable can be modified according to demand, the proposal or more than 0.5 is better, otherwise the original will not see clearly.

Image overlay for Android image effects processing

Related Article

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.