2011-12-09 36 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