だから私はCanvasの方法に問題があります。DrawBitmap()、予期しない結果を描画します。
私の例を見てみましょう:
ソース画像
私は2つのケースを持っています(テストのためだけに):
- 私は0,0から赤い四角形を描画し、彼にイメージのサイズ1/4を与えたいです。また、このビットマップを同じサイズ (1/4) で描画し、Bottom.Right の場所に配置したいと考えています。
- 同じ条件 ( Top.Left (0,0) から開始し、画像の 1/4 のサイズ) で再度赤い四角形を描画し、ビットマップの一部を描画して、1/4 サイズ ( Bottom.Right ) の Rectangle として表示します。
ケース #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);
だから私は理解できません、なぜそれが起こるのですか?(サイズに合わせてスケーリングせず、長方形を複製するのはなぜですか?)
何か案は?ありがとう!