Reputation: 227
I'm trying to show part of an image in an ImageView
. I tried it with canvas.drawBitmap()
but it seems like the false part of the image is displayed. My code:
MainActivity:
this.drawCharacter = new DrawCharacter(1);
this.bm = Bitmap.createBitmap(16, 32, Bitmap.Config.ARGB_8888);
this.c = new Canvas(this.bm);
this.c = this.drawCharacter.drawCharacter(this.c, this.characterBitmap);
this.bm = Bitmap.createScaledBitmap(this.bm, this.imgWidth, this.imgHeight, isChild());
this.imgv.setImageBitmap(this.bm);
DrawCharacter:
[...]
Paint localPaint = new Paint();
paramCanvas.drawBitmap(paramBitmap, new Rect(8, 8, 16, 16), new Rect(4, 0, 12, 8), localPaint);
return paramCanvas;
[...]
And at the end some strange part of the image is shown.
Upvotes: 0
Views: 74
Reputation: 4688
In your drawBitmap()
call, you set the first Rect parameter to 8,8,16,16, this is the source rectangle from your bitmap to be drawn, set it to null to draw the entire bitmap.
if you want to apply this bounds according to the initial bitmap scale, you may need to apply the same scale on your src Rectangle.
(try to remove the scale part, createScaledBitmap()
to see if your src rectangle is good without the scale ;) )
Upvotes: 1