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

简易画图

时间:2016-07-21 14:29:47      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

    private ImageView iv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        iv = (ImageView) findViewById(R.id.iv);
        final Bitmap bitmap = BitmapFactory.decodeFile("/storage/sdcard/blank_500_500.png");
        //只能在副本图片上修改
        final Bitmap copyBitmap = Bitmap.createBitmap(bitmap.getWidth(),bitmap.getHeight(),bitmap.getConfig());
        final Canvas canvas = new Canvas(copyBitmap);
        final Paint paint = new Paint();
        paint.setColor(Color.RED);
        //线的宽度
        paint.setStrokeWidth(6);
        if (bitmap != null) {
            iv.setImageBitmap(copyBitmap);
        }
        iv.setOnTouchListener(new View.OnTouchListener() {
            int startX = 0;
            int startY = 0;
            int endX = 0;
            int endY = 0;
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        startX = (int) event.getX();
                        startY = (int) event.getY();
                    case MotionEvent.ACTION_UP:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        endX = (int) event.getX();
                        endY = (int) event.getY();
                        canvas.drawLine(startX,startY,endX,endY,paint);
                        startX = endX;
                        startY = endY;
                        iv.setImageBitmap(copyBitmap);
                }
                return true;//true
            }
        });
    }

SD卡权限

简易画图

标签:

原文地址:http://www.cnblogs.com/linson0116/p/5691354.html

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