我有一个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
答案 0 :(得分: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);
}