Hoping someone can help, i’m trying to work out how to transform an image from a rectangle to a quadrilateral with given x,y screen coordinates for each corner.
So far I have put the image on a CALayer but need to work out the CATransform3D to warp the rectangle to needed quadrilateral. An example of what I am trying to achieve is below (from a to b).
If I am wrong and cant be done using CATransform3D is there any other way this can be achieved with a example please.
I think KennyTM’s answer is close to what i need from here..
iPhone image stretching (skew)
I have tried it and not had much luck, he does mention “you may need a transpose” but if that is the case I’m not sure what to do.
CATransform 3D can definitely do what you are trying to use it for. I tested out the code you linked to and it worked perfectly for me. Remember that a transformation matrix like that is defined only up to a scale because it is in homogeneous coordinates. Once you generate the matrix with his equations divide each element by the bottom right element. The only reason I can think of that you would need a transpose would be because the transform he gives is in row major order. If you are filling a column major transformation matrix (which I believe CATransform3D is) you need to transpose it after you fill it.
Here is the code I used to test it, It uses matrix classes from openCV and is in c++ but should prove the point
After executing, all test variables at the bottom matched their quad counterparts perfectly. Hopefully that clears things up.