怎么在Android中利用帆布对象实现一个刮刮乐效果

  介绍

这篇文章将为大家详细讲解有关怎么在Android中利用帆布对象实现一个刮刮乐效果,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

<强>布局文件

& lt; FrameLayout  xmlns: Android=? http://schemas.android.com/apk/res/android",,   xmlns:才能工具=?http://schemas.android.com/tools",,   android:才能layout_width=癿atch_parent",   android:才能layout_height=癿atch_parent",在,   ,   & lt;才能ImageView    ,,,android: id=癅 + id/after",   ,,,android: layout_width=皐rap_content",   ,,,android: layout_height=皐rap_content",   ,,,android: src=https://www.yisu.com/zixun/" @drawable/"/>            

活动代码

public  class  MainActivity  extends  Activity  implements  OnTouchListener  {,   ,   private 才能;ImageView  imgafter;,   private 才能;ImageView  imgbefore;,   private 才能Canvas 画布,   private 才能Paint 油漆,   private 才能Bitmap 位图,   private 才能Bitmap 之前,   private 才能Bitmap 之后,   ,   @Override 才能;   protected 才能;void  onCreate (Bundle  savedInstanceState), {,   ,,,super.onCreate (savedInstanceState);,   ,,,setContentView (R.layout.activity_main);,   ,   ,,,imgafter =, (ImageView), findViewById (R.id.after);,   ,,,imgbefore =, (ImageView), findViewById (R.id.before);,   ,   ,,,//,获得图片,   ,,,after =, BitmapFactory.decodeResource (getresource (),, R.drawable.a),,   ,,,before =, BitmapFactory.decodeResource (getresource (),, R.drawable.b),,   ,   ,,,imgafter.setImageBitmap(后),,   ,,,imgbefore.setImageBitmap(之前),,   ,,,//,创建可以修改的空白的bitmap    ,,,bitmap =, Bitmap.createBitmap (before.getWidth (),, before.getHeight (),,   ,,,,,,,before.getConfig ()),,   ,,,imgbefore.setOnTouchListener(这个),,   ,,,paint =, new 油漆();,   ,,,paint.setStrokeWidth (5),,   ,,,paint.setColor (Color.BLACK);,   ,,,//,创建画布,   ,,,canvas =, new 画布(位图),,   ,,,canvas.drawBitmap(之前,new 矩阵(),油漆),,   ,,},   ,   @Override 才能;   public 才能;boolean  ondraw (View  arg0, MotionEvent 事件),{,   ,,,switch  (event.getAction ()), {,   ,,,case  MotionEvent.ACTION_MOVE:,   ,,,,,int  newX =, (int), event.getX (),,   ,,,,,int  newY =, (int), event.getY (),,   ,,,,,//,将滑过的地方变为透明,   ,,,,,for  (int 小姐:=,-10;,小姐:& lt;, 10;,我+ +),{,   ,,,,,,,for  (int  j =, -10;, j  & lt;, 10;, j + +), {,   ,,,,,,,,,if ((小姐:+,newX),祝辞=,before.getWidth (),   ,,,,,,,,,,,,,| |,j  +, newY 祝辞=,before.getHeight(), | |,小姐:+,newX  & lt;, 0,   ,,,,,,,,,,,,,| |,j  +, newY  & lt;, 0), {,   ,,,,,,,,,,,return 假的,,   ,,,,,,,,,},   ,,,,,,,,,bitmap.setPixel(小姐:+,newX,, j  +, newY,, Color.TRANSPARENT),,   ,,,,,,,},   ,,,,,},   ,,,,,imgbefore.setImageBitmap(位图),,   ,,,,,休息,,   ,,,},   ,,,return ,真的,,   ,,},   null

怎么在Android中利用帆布对象实现一个刮刮乐效果