Android Image Processing series seven-image doodle, watermark-picture overlay

Source: Internet
Author: User

Picture graffiti and Watermark is actually a function, the way to achieve is the same, is a large picture and a small picture overlay can be. Front in the Android image processing series six-to add a border to the picture (bottom)-The picture overlay also describes the picture overlay, the principle is to directly manipulate the pixel point. Here's a way to overlay a picture--using canvas to manipulate the picture, the canvas is already encapsulated, and the direct call is done.

Here's how it works:

+ =

Code:

[Java]View PlainCopy
  1. /**
  2. * Combine graffiti pictures and source images
  3. * @param src source image
  4. * @param watermark Graffiti Pictures
  5. * @return
  6. */
  7. Public Bitmap Doodle (Bitmap src, Bitmap watermark)
  8. {
  9. //Create an additional picture
  10. Bitmap newb = Bitmap.createbitmap (Src.getwidth (), Src.getheight (), config.argb_8888); //Create a new bitmap with the same src length width
  11. Canvas canvas = new Canvas (NEWB);
  12. Canvas.drawbitmap (SRC, 0, 0, null); Start drawing the original image in 0, 0 coordinates src
  13. Canvas.drawbitmap (Watermark, (Src.getwidth ()-watermark.getwidth ())/ 2, (Src.getheight ()-Watermark.getheight () )/ 2, null); //Graffiti pictures to the middle of the original picture position
  14. Canvas.save (Canvas.all_save_flag);
  15. Canvas.restore ();
  16. Watermark.recycle ();
  17. watermark = null;
  18. return newb;
  19. }


In front of the same, to note that the picture is best placed in the assets directory, pay attention to the picture recycling, or the picture will cause memory tension. This superposition way generally choose PNG format picture as graffiti picture or watermark, of course also can use JPG, that need to follow the above mentioned Android image processing series of six-to the picture to add a border (bottom)-image overlay pixel filtering, which will affect the processing speed, So it is not recommended to use JPG image, if can write more efficient algorithm, also can.

In addition, when doing graffiti, the demand may be that the user can hold down the graffiti picture, and then drag the effect. In this case, I give a thought, rewrite ImageView inside the Ontouchevent method, Motionevent.getaction () inside there are three states, Motionevent.action_down, Motionevent.action_up and Motionevent.action_move, according to these three states to determine the user's behavior, decide whether to move the picture, in addition to be careful to determine whether the graffiti pictures moved to the edge of the original picture. Because this part of the code is the same as the cropping, it is not good to paste it out, so give everyone a thought, the following will be the code to paste out the clip.

OK, this article is written here, there is a way to overlay the picture, please look forward to!

Android Image Processing series seven-image doodle, watermark-picture overlay

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.