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
- /**
- * Combine graffiti pictures and source images
- * @param src source image
- * @param watermark Graffiti Pictures
- * @return
- */
- Public Bitmap Doodle (Bitmap src, Bitmap watermark)
- {
- //Create an additional picture
- Bitmap newb = Bitmap.createbitmap (Src.getwidth (), Src.getheight (), config.argb_8888); //Create a new bitmap with the same src length width
- Canvas canvas = new Canvas (NEWB);
- Canvas.drawbitmap (SRC, 0, 0, null); Start drawing the original image in 0, 0 coordinates src
- Canvas.drawbitmap (Watermark, (Src.getwidth ()-watermark.getwidth ())/ 2, (Src.getheight ()-Watermark.getheight () )/ 2, null); //Graffiti pictures to the middle of the original picture position
- Canvas.save (Canvas.all_save_flag);
- Canvas.restore ();
- Watermark.recycle ();
- watermark = null;
- return newb;
- }
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