Android – Canvas在ImageView中drawLine

我有一个ImageView,我想绘制一条线。 我做了以下事情:

mImagenCampo = (ImageView) findViewById(R.id.imagen_campo); 

crearPunto(mArea9M, mPaloIzq,v.getWidth(), mPaloIzq,Color.WHITE);

function是:

 private void crearPunto(float x, float y, float xend, float yend, int color) { BitmapDrawable bmpDraw = (BitmapDrawable) mImagenCampo.getDrawable(); Bitmap bmp = bmpDraw.getBitmap().copy(Config.RGB_565, true); Canvas c = new Canvas(bmp); Paint p = new Paint(); p.setColor(color); c.drawLine(x, y, xend, yend, p); mImagenCampo.setImageBitmap(bmp); } 

我的问题是,线被绘制,但它没有得到的权利坐标。 它被画得比它应该小。

谢谢

编辑:我忘了说, mImagenCampo是一个ImageView

Solutions Collecting From Web of "Android – Canvas在ImageView中drawLine"

尝试这个:

 private void crearPunto(float x, float y, float xend, float yend, int color) { bmp = Bitmap.createBitmap(mImagenCampo.getWidth(), mImagenCampo.getHeight(), Config.ARGB_8888); c = new Canvas(bmp); mImagenCampo.draw(c); Paint p = new Paint(); p.setColor(color); c.drawLine(x, y, xend, yend, p); mImagenCampo.setImageBitmap(bmp); }