所以我对 Canvas 的方法有疑问。DrawBitmap(),绘制出意外的结果。
让我们看看我的例子:
源图像
我有两个案例(仅供测试):
- 我想从0,0绘制红色矩形并给他1/4大小的图像,我也想以相同大小(1/4)绘制这个位图并放在底部。正确的地方。
- 再次绘制具有相同条件的红色矩形(从Top.Left (0,0) 和图像大小的 1/4 开始)并绘制位图的一部分并显示为 1/4 大小的矩形(Bottom.Right)。
情况1
我正在这样做:
//source imageview
Source.SetImageResource(Resource.Drawable.lena30);
//bitmap
bt = ((BitmapDrawable)Source.Drawable).Bitmap.Copy(Bitmap.Config.Argb8888, true);
//second imageview, where i fill result
Draw.SetImageBitmap(bt);
can = new Canvas(bt);
Paint paint = new Paint();
paint.Color = Color.Red;
paint.SetStyle(Paint.Style.Fill);
//draw Red Rect with 1/4 size and locate Top.Left
can.DrawRect(0,0,bt.Width/2,bt.Height/2,paint);
//redraw new bitmap(all subset) and locate to Bottom.Right with 1/4 size
can.DrawBitmap(bt, null, new Rect(bt.Width/2, bt.Height / 2, bt.Width, bt.Height), null);
案例#2
相同,但现在成为位图的一部分(不是位图的完整子集):
//source imageview
Source.SetImageResource(Resource.Drawable.lena30);
//bitmap
bt = ((BitmapDrawable)Source.Drawable).Bitmap.Copy(Bitmap.Config.Argb8888, true);
//second imageview, where i fill result
Draw.SetImageBitmap(bt);
can = new Canvas(bt);
Paint paint = new Paint();
paint.Color = Color.Red;
paint.SetStyle(Paint.Style.Fill);
//draw Red Rect with 1/4 size and locate Top.Left
can.DrawRect(0,0,bt.Width/2,bt.Height/2,paint);
//redraw new bitmap(not full,only part of Source Rectangle) and locate to Bottom.Right with 1/4 size
can.DrawBitmap(bt, new Rect(bt.Width/2,0,bt.Width,bt.Height), new Rect(bt.Width/2, bt.Height / 2, bt.Width, bt.Height), null);
所以我不明白,为什么会这样?(为什么图像没有缩放以适应大小并重复矩形!?)。
有任何想法吗?谢谢!