码迷,mamicode.com
首页 > 其他好文 > 详细

撕衣服案例

时间:2019-01-10 22:57:54      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:getconf   find   vat   out   pre   rri   rac   cat   boolean   

撕衣服案例

public class MainActivity extends AppCompatActivity {
    private ImageView iv;

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = findViewById(R.id.iv);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.pre19);
        final Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
        Paint paint = new Paint();
        final Canvas canvas = new Canvas(bitmap1);
        canvas.drawBitmap(bitmap, new Matrix(), paint);
        iv.setImageBitmap(bitmap1);
        iv.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_MOVE:
                        for (int i = 0; i < 20; i++) {
                            for (int j = 0; j < 20; j++) {
                                try {
                                    bitmap1.setPixel((int) event.getX() + i, (int) event.getY() + j, Color.TRANSPARENT);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                        iv.setImageBitmap(bitmap1);
                }
                return true;
            }
        });
    }
}

 

撕衣服案例

标签:getconf   find   vat   out   pre   rri   rac   cat   boolean   

原文地址:https://www.cnblogs.com/nangongyibin/p/10252683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!