2011-12-09 22 views
8

我有一个ImageView,我想绘制一条线。我已经做了如下:Android - Canvas drawLine ImageView

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

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

而且功能:

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的

回答

16

试试这个:

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); 
} 
+1

非常感谢。它工作完美。 – gutiory