Skip to content
Advertisement

how to draw prespctive image in android canvas

i have searched about how to draw prespctive image in canvas like in the picture but i dont find anything thing. if its not possible using canvas, how i can make something like it? image

i find this:-

Bitmap bitmap1=BitmapFactory.decodeResource(getResources(), R.drawable.img1);
Bitmap bitmap2=BitmapFactory.decodeResource(getResources(), R.drawable.img1);
Paint paint = new Paint();
paint.setAntiAlias(true);
Canvas canvas = new Canvas(resultingImage);
Path path=new Path();
path.moveTo(0,0);
float mm=1000;
path.lineTo(mm,0);
path.lineTo(mm, mm);
path.lineTo(0, mm);
path.lineTo(0,0);
canvas.drawPath(path, paint);

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap2, 0, 0, paint);
img.setImageBitmap(resultingImage);

but this cut the image.

Advertisement

Answer

This is possible by magic method of canvas drawBitmapMesh.

This is example from my project:

static void Draw( Canvas canvas, Rect rt, Ini ini ){
    final int sections = 256;
    Point size = new Point();
    float[] verts = Mesh.GetVertices( rt, sections, ini, size );
    canvas.drawBitmapMesh( ini.bm, size.x, size.y, verts, 0, null, 0, null );
}

enter image description here

Advertisement