Android - Canvas drawLine inside ImageView

孤者浪人 提交于 2019-11-30 03:37:28

问题


I've one ImageView in which I want to draw a Line. I've done the follow:

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

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

And the function is:

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);

}

My problem is that the line is drawn but It doesn't get the rights coordinates. It is drawn smaller than It should be.

Thanks

Edit: I forgot to say that mImagenCampo is an ImageView


回答1:


Try this:

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


来源:https://stackoverflow.com/questions/8445161/android-canvas-drawline-inside-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!