Hi,
I want to draw a bitmap into a shape (in this case an isosceles
trapezoid); not clipped, but with the bitmap transformed to fit the
shape. For example, if the height of the left side is greater than
that of the right side then I want the bitmap evenly transformed in
height from left to right to match the height difference. The only
method I can find to do this is drawBitmapMesh, however this produces
some strange results. I have searched extensively and can find no
concrete information on drawBitmapMesh.
To demonstrate the example, I have a bitmap which contains an even
grid of vertical and horizontal lines. I use bitmap mesh with the code
shown below. However, the horizontal lines of the grid do not evenly
merge downwards from the top and upwards from the bottom towards the
target. Rather, horizontal lines to the left of the line dissecting
the top-left to bottom-right diagonal of the shape slant downwards to
the left, lines to the right of the same diagonal slant downwards to
the right. I also note that that the top line of the bitmap increases
slightly in height from left before descending again to the right.
Perhaps drawBitmapMesh is not the method I should be using, or perhaps
I am using it incorrectly. If anyone could enlighten me on how to
accomplish my aim I would be most grateful.
@Override
protected void dispatchDraw(Canvas canvas)
{
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.grid_bitmap);
Rect rect = new Rect();
this.getDrawingRect(rect);
float[] verts = new float[8];
verts[0] = rect.left;
verts[1] = rect.top;
verts[2] = rect.right;
verts[3] = rect.top + 100;
verts[4] = rect.left;
verts[5] = rect.bottom;
verts[6] = rect.right;
verts[7] = rect.bottom - 100;
canvas.drawBitmapMesh(bitmap, 1, 1, verts, 0, null, 0, null);
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en