Android 无法在可变图像上绘制

Android 无法在可变图像上绘制,android,Android,我试图用下面提到的代码在从内存加载的图像上画线,但它不起作用 imgView = (ImageView) findViewById(R.id.imageView); bitmap = BitmapFactory.decodeFile(img1.getAbsolutePath()).copy(Bitmap.Config.ARGB_8888,true); canvas = new Canvas(bitmap); paint = new Paint(Paint.ANTI_ALIAS_FLAG)

我试图用下面提到的代码在从内存加载的图像上画线,但它不起作用

 imgView = (ImageView) findViewById(R.id.imageView);
 bitmap = BitmapFactory.decodeFile(img1.getAbsolutePath()).copy(Bitmap.Config.ARGB_8888,true);
 canvas = new Canvas(bitmap);
 paint = new Paint(Paint.ANTI_ALIAS_FLAG);
 paint.setColor(Color.RED);
 imgView.setImageBitmap(bitmap);
 imgView.setOnTouchListener(this);
但当我将代码更改为:

    imgView = (ImageView) findViewById(R.id.imageView);
    bitmap = Bitmap.createBitmap((int) dw, (int) dh, Bitmap.Config.ARGB_8888);;
     canvas = new Canvas(bitmap);
     paint = new Paint(Paint.ANTI_ALIAS_FLAG);
     paint.setColor(Color.RED);
     imgView.setImageBitmap(bitmap);
     imgView.setOnTouchListener(this);
我能用手指画线

有什么建议吗

OnTouchCodeListner函数


这可能是因为它无法使其可变。试用

Bitmap.createBitmap(BitmapFactory.decodeFile(img1.getAbsolutePath()),dw,dh);

我们能看看你的触控监听代码吗?@JasonOfEarth我已经更新了这个问题
Bitmap.createBitmap(BitmapFactory.decodeFile(img1.getAbsolutePath()),dw,dh);