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
- /**
- * Image Effect Overlay
- * @param bmp limits the size of the bitmap
- * @return
- */
- Private Bitmap Overlay (Bitmap BMP)
- {
- Long start = System.currenttimemillis ();
- int width = bmp.getwidth ();
- int height = bmp.getheight ();
- Bitmap Bitmap = bitmap.createbitmap (width, height, Bitmap.Config.RGB_565);
- //Zoom in on a border picture
- Bitmap overlay = Bitmapfactory.decoderesource (Mcontext.getresources (), r.drawable.rainbow_overlay);
- int w = overlay.getwidth ();
- int h = overlay.getheight ();
- float ScaleX = width * 1F/W;
- float ScaleY = height * 1f/h;
- Matrix matrix = new Matrix ();
- Matrix.postscale (ScaleX, ScaleY);
- Bitmap overlaycopy = Bitmap.createbitmap (overlay, 0, 0, W, h, Matrix, true);
- int pixcolor = 0;
- int laycolor = 0;
- int pixr = 0;
- int pixg = 0;
- int pixb = 0;
- int pixA = 0;
- int newr = 0;
- int NEWG = 0;
- int newb = 0;
- int Newa = 0;
- int Layr = 0;
- int layg = 0;
- int layb = 0;
- int layA = 0;
- final Float alpha = 0.5F;
- int[] srcpixels = new int[width * height];
- int[] laypixels = new int[width * height];
- Bmp.getpixels (Srcpixels, 0, width, 0, 0, width, height);
- Overlaycopy.getpixels (Laypixels, 0, width, 0, 0, width, height);
- int pos = 0;
- For (int i = 0; i < height; i++)
- {
- For (int k = 0; k < width; k++)
- {
- pos = i * width + k;
- Pixcolor = Srcpixels[pos];
- Laycolor = Laypixels[pos];
- PIXR = Color.Red (Pixcolor);
- Pixg = Color.green (Pixcolor);
- PIXB = Color.Blue (Pixcolor);
- PixA = Color.alpha (Pixcolor);
- Layr = Color.Red (Laycolor);
- LAYG = Color.green (Laycolor);
- Layb = Color.Blue (Laycolor);
- LayA = Color.alpha (Laycolor);
- NEWR = (int) (PIXR * alpha + Layr * (1-alpha));
- NEWG = (int) (PIXG * alpha + LAYG * (1-alpha));
- Newb = (int) (PIXB * alpha + Layb * (1-alpha));
- LayA = (int) (PixA * alpha + LayA * (1-alpha));
- NEWR = Math.min (255, Math.max (0, NEWR));
- NEWG = Math.min (255, Math.max (0, NEWG));
- Newb = Math.min (255, Math.max (0, newb));
- Newa = Math.min (255, Math.max (0, LayA));
- Srcpixels[pos] = Color.argb (Newa, NEWR, NEWG, newb);
- }
- }
- Bitmap.setpixels (Srcpixels, 0, width, 0, 0, width, height);
- Long end = System.currenttimemillis ();
- LOG.D ("may", "Overlayameliorate used time=" + (End-start));
- return bitmap;
- }
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