Here is a way to add a lace border with a transparent picture overlay, and here's another way to add a lace border to a picture overlay. The previous method has a disadvantage, is to make a PNG picture, the picture volume will be very large, not the general large, three times times larger than the same JPG, if the project can ignore the size of the package, then you can use the previous treatment method, although this article can reduce the volume of the picture, but the processing is more complex, and I am not very mature research This article is for JPG border processing, but the disadvantage is not mature enough, only provide ideas.
Idea: You can make the border into a jpg picture, no border place, is generally the middle area to adjust to special colors, such as black. In the two pictures overlay, the border picture to do special processing, such as the black Point filter out, change the border image pixel transparency, you can complete the effect of the previous PNG picture.
Here's how it works:
+ =
At present, the code processing is not very good, non-black dots and black point of the junction did not do fuzzy processing, the specific method behind the article will be discussed. The same border picture is suggested to be placed in the assets directory.
Paste the following code:
[Java]View PlainCopy
- <pre name="code" class="java" >/**
- * Overlay Border Picture useful parts
- * @param bmp
- * @return
- */
- private Bitmap Alphalayer (Bitmap bmp)
- {
- int width = bmp.getwidth ();
- int height = bmp.getheight ();
- Bitmap Bitmap = bitmap.createbitmap (width, height, Bitmap.Config.RGB_565);
- //Border picture
- Bitmap overlay = Bitmapfactory.decoderesource (Mcontext.getresources (), r.drawable.black);
- 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 newcolor = 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;
- float alpha = 0.3F;
- float Alphar = 0F;
- float alphag = 0F;
- float AlphaB = 0F;
- For (int i = 0; i < width; i++)
- {
- For (int k = 0; k < height; k++)
- {
- Pixcolor = Bmp.getpixel (i, k);
- Laycolor = Overlaycopy.getpixel (i, k);
- //Get the RGBA value of the original picture
- PIXR = Color.Red (Pixcolor);
- Pixg = Color.green (Pixcolor);
- PIXB = Color.Blue (Pixcolor);
- PixA = Color.alpha (Pixcolor);
- //Get the RGBA value of the border picture
- Layr = Color.Red (Laycolor);
- LAYG = Color.green (Laycolor);
- Layb = Color.Blue (Laycolor);
- LayA = Color.alpha (Laycolor);
- //colors similar to pure black dots
- if (Layr < && Layg < && Layb < )
- {
- Alpha = 1F;
- }
- Else
- {
- Alpha = 0.3F;
- }
- Alphar = Alpha;
- Alphag = Alpha;
- AlphaB = Alpha;
- //Two colors overlay
- NEWR = (int) (PIXR * Alphar + Layr * (1-alphar));
- NEWG = (int) (PIXG * alphag + LAYG * (1-alphag));
- Newb = (int) (PIXB * AlphaB + Layb * (1-alphab));
- LayA = (int) (PixA * alpha + LayA * (1-alpha));
- //value between 0~255
- 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));
- Newcolor = Color.argb (Newa, NEWR, NEWG, newb);
- Bitmap.setpixel (i, K, Newcolor);
- }
- }
- return bitmap;
- }
This way the picture processing is relatively slow, because the pixel points to a getpixel (), the composition of the new picture when a setpixel (). In addition you can use Getpixels (), and setpixels () method, this processing to a little faster, I have other similar effects of the treatment test, the back processing way than the front 3 times faster. Because this image overlay is for pixel processing, it is the next special effect processing series, because it involves the picture overlay, so put it in front. How to use it, it will be discussed later, and readers can study it themselves. The optimized code will be posted later, so please look forward to it.
Android Image Processing Series VI-Add a border to a picture (bottom)-Picture overlay