The previous article about the way to add a border to the picture, only to add some rules to the image of the border, if you want to add some more beautiful effect, it is a bit troublesome. Here is the idea to solve this problem.
The idea is: some of the more beautiful lace pictures We are very difficult to control with the code, on the current level is not up to, do not exclude cattle, and then PS those effects are programmers to make, there must be a way to achieve, which may involve a very complex graphics. Pull away, and then how to use those beautiful lace as the frame of the picture. The simple way is to overlay two pictures. The simplest one is this article, with a transparent PNG format picture. Because Android is supported PNG image processing, and PNG image has transparency value, so, add those lace border can first make the picture completely transparent (art to do the picture when you can create a full-transparent picture, and then add lace to the picture.) ), and then stack it up to OK. Note that the border has a size, preferably larger, if you want to deal with a larger picture, you can first zoom to a certain proportion, and then add a border, if the border is larger than the picture, the first to scale the border, specific zoom see the previous Android image processing series two--image rotation, zoom, invert, There is no code on the side.
Less nonsense, see below: (When the picture size is not the same, more ugly)
+
=
Code:
The res here is the border picture, or the same, not recommended to put under drawable, and finally put in the assets directory, why not say it
[Java]View PlainCopy
- /**
- * Add border
- * @param BM Original picture
- * @param res Border Resource
- * @return
- */
- Private Bitmap Addbigframe (Bitmap BM, int res)
- {
- Bitmap Bitmap = Decodebitmap (res);
- drawable[] Array = new drawable[2];
- array[0] = new bitmapdrawable (BM);
- Bitmap B = Resize (Bitmap, Bm.getwidth (), Bm.getheight ());
- array[1] = new bitmapdrawable (b);
- layerdrawable layer = new layerdrawable (array);
- return Drawabletobitmap (layer);
- }
- /**
- * Convert drawable to bitmap
- * @param drawable
- * @return
- */
- Private Bitmap Drawabletobitmap (drawable drawable)
- {
- Bitmap Bitmap = Bitmap.createbitmap (Drawable.getintrinsicwidth (), Drawable.getintrinsicheight (), Drawable.getopacity ()! = Pixelformat.opaque? Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565);
- Canvas canvas = new canvas (bitmap);
- //Canvas.setbitmap (bitmap);
- Drawable.setbounds (0, 0, Drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());
- Drawable.draw (canvas);
- return bitmap;
- }
- /**
- * Convert r.drawable.* to bitmap
- * @param Res
- * @return
- */
- Private Bitmap decodebitmap (int res)
- {
- return Bitmapfactory.decoderesource (Mcontext.getresources (), res);
- }
Android Image Processing series five-add a border to a picture (middle)