我们可以通过矩形构造位图吗?Android:从RECT构造位图
我在矩形中绘制位图,并希望在位图图像上绘制的笔画成为图像的一部分。
我想知道是否可以从Rect构造位图,以便新位图将旧图像和笔画作为单个图像。
谢谢
我们可以通过矩形构造位图吗?Android:从RECT构造位图
我在矩形中绘制位图,并希望在位图图像上绘制的笔画成为图像的一部分。
我想知道是否可以从Rect构造位图,以便新位图将旧图像和笔画作为单个图像。
谢谢
你总是可以采取一个画布,以帮助您创建一个已解码的位图,你所希望的方式:
Bitmap originalBmp = null;//Here goes original Bitmap...
ImageView img = null;//Any imageview holder you are using...
Bitmap modifiedBmp = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);//Configure with your proper size and color
Canvas canvas = new Canvas(modifiedBmp);
//At this point the modified bitmap has the original one, starting from here, you can add any overlay you want...
canvas.drawBitmap(originalBmp, 0, 0, new Paint());
//And do all the other modifications you want here...
canvas.drawLines(new float[]{}, null);
canvas.drawCircle(x, y, radius, null);
//At this point the modified bitmap will have anything you added
img.setImageBitmap(modifiedBmp);
// IF YOU ARE OVERRIDING ONDRAW METHOD
public void onDraw(Canvas canvas){
//Here DO your DRAW BITMAP NOTE: paint must be already created...
canvas.drawBitmap(bt, 0, 0, paint);
paint.setColor(Color.BLACK);
paint.setStrokeWidth(3);
canvas.drawRect(30, 30, 80, 80, paint);
super.onDraw(canvas);
}
商祺!
感谢您的建议:) 但是我已经在画布上绘制了一个位图,在绘制方法 canvas.drawBitmap(bt,null,cardPicRect,p); 其中bt是我的位图,cardPicRect是Rect,我在其中绘制位图,p是绘画对象。 我不确定我是否可以用位图构建一个新的画布。我可以在画布上构造一个画布吗? – Aniket
如果你正在重写onDraw(Canvas canvas),你可以在方法“canvas.drawBitmap(bt,null,cardPicRect,p);”之后用线添加另一个调用来制作矩形框。你已经有 –
嗨马丁感谢您的快速反应。 但我不明白你的意思是你可以添加另一个电话,使行矩形框 你能请我解释一下 谢谢 – Aniket
是的,你可以,使用画布,你可以在你的旧bimtap上画一些东西。
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
// do some canvas drawing
canvas.drawBitmap(bitmap, rect, rect, paint);
谢谢对于这个建议:) 但是我已经在canvas的绘制方法 画布上绘制了一个位图。drawBitmap(BT,NULL,cardPicRect,P); 其中bt是我的位图,cardPicRect是Rect中我绘制位图和p是绘画对象。 我不确定是否可以用位图构建一个新的画布。我可以在画布上构造一个画布吗? – Aniket
afaik,你可以用位图创建一个画布,并在同一个画布上绘制矩形/笔画,现在你的位图上会有图形。试一试 – Varun