The main principle is: Extends view overload ondrow (), need a bitmap, overload view, the canvas to draw temporary BMP, when pressed to determine the time to press
Draw on the real_bmp, the other front surface basically no difference.
Import Com.example.test.r;import Android.app.activity;import Android.content.context;import Android.graphics.bitmap;import Android.graphics.canvas;import Android.os.bundle;import Android.provider.contactscontract.commondatakinds.event;import Android.util.attributeset;import Android.util.Log ; Import Android.view.motionevent;import Android.view.view;public class Bmpeffect extends activity{/* requires a bitmap, overloaded vie W, in the canvas to draw temporary BMP, when pressed to determine the time to press the * draw to Real_bmp, the other front face basically no difference */private static Bitmap src;private static Bitmap HEART;PR Ivate static Bitmap star;private static Bitmap star2;private static int choose;private int Height;private int Width;public static float bmp_x; public static float bmp_y;private Canvas my_canvas;public void OnCreate (Bundle save) {LOG.E ("on Create", "Hello"); Super.oncreate (save); Src=data.src_bmp; if (data.src_bmp==null) log.e ("BMP", "null"); My_canvas=new canvas (data.src_bmp); Height=data.src_bmp.getheight (); Width=data.src_bmp.getwidth (); Heart=data.geTbmp (Getresources (), R.drawable.small_heart); Star=data.getbmp (Getresources (), R.drawable.small_star); Star2=data.getbmp (Getresources (), R.DRAWABLE.STAR8); choose=0; Setcontentview (r.layout.bmptest); } public void On_star2 (final View v) {//star8; choose=3; } public void On_star (final View v) {choose=2; } public void On_heart (final View v) {choose=1; public void On_ok (final View v) {drow_bmp (My_canvas); public static void Drow_bmp (canvas canvas) {switch (choose) {Case 1:canvas.drawbitmap (heart, bmp_x, bmp_y, NULL); Break Case 2:canvas.drawbitmap (star, bmp_x,bmp_y, NULL); Break Case 3://canvas.drawbitmap (star2, Matrix, Paint) Canvas.drawbitmap (star2, bmp_x, bmp_y, NULL); }} public static class Bmpview extends View{public Bmpview (Context context,attributeset attrs) {super (CONTEXT,ATTRS);// TODO auto-generated constructor stub} protected void OnDraw (canvas canvas) {canvas.drawcolor (0xff000000); LOG.I ("Canvas", "Drow"); if (src!=null) {Canvas.drawbitmaP (SRC, 0, 0, NULL); } drow_bmp (canvas); } public boolean ontouchevent (Motionevent event) {int action=event.getaction ();//should now be able to not distinguish between different gesture events, only need to get bmp_x= Event.getx (); Bmp_y=event.gety (); Invalidate (); return true; } } }
The effect is as follows