Android Image Processing series five-add a border to a picture (middle)

Source: Internet
Author: User

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
  1. /**
  2. * Add border
  3. * @param BM Original picture
  4. * @param res Border Resource
  5. * @return
  6. */
  7. Private Bitmap Addbigframe (Bitmap BM, int res)
  8. {
  9. Bitmap Bitmap = Decodebitmap (res);
  10. drawable[] Array = new drawable[2];
  11. array[0] = new bitmapdrawable (BM);
  12. Bitmap B = Resize (Bitmap, Bm.getwidth (), Bm.getheight ());
  13. array[1] = new bitmapdrawable (b);
  14. layerdrawable layer = new layerdrawable (array);
  15. return Drawabletobitmap (layer);
  16. }
  17. /**
  18. * Convert drawable to bitmap
  19. * @param drawable
  20. * @return
  21. */
  22. Private Bitmap Drawabletobitmap (drawable drawable)
  23. {
  24. Bitmap Bitmap = Bitmap.createbitmap (Drawable.getintrinsicwidth (), Drawable.getintrinsicheight (), Drawable.getopacity ()! = Pixelformat.opaque? Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565);
  25. Canvas canvas = new canvas (bitmap);
  26. //Canvas.setbitmap (bitmap);
  27. Drawable.setbounds (0, 0, Drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());
  28. Drawable.draw (canvas);
  29. return bitmap;
  30. }
  31. /**
  32. * Convert r.drawable.* to bitmap
  33. * @param Res
  34. * @return
  35. */
  36. Private Bitmap decodebitmap (int res)
  37. {
  38. return Bitmapfactory.decoderesource (Mcontext.getresources (), res);
  39. }

Android Image Processing series five-add a border to a picture (middle)

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.