Stretch Bitmap at specific corner

android, bitmap, camera, matrix, transform

Solution

You made me look into this very interesting problem and it seems easy to do it in Android. Use absolute coordinates for the four points of the Mesh:

float[] mVerts = {
       topLeftX, topLeftY, 
       topRightX, topRightY, 
       bottomLeftX, bottomLeftY, 
       bottomRightX, bottomRightY
       };

canvas.drawBitmapMesh(myImage, 1, 1, mVerts, 0, null, 0, null);

You would have to figure out how to get these points but drawBitmapMesh will stretch it for you.

Problem

Is it possible to stretch a Bitmap at a specific corner? The picture below shows my intention: I shoot a picture with the camera, detect the corners in the image and want to transform the content. As far as I know this can't be achieved with the Matrix class alone. The Camera class should help, but I would need to calculate the camera's position. Is there an algorithm for this purpose? How would you do this?

Original source