Search code examples
objective-cioscocoa-touchquartz-2d

cropping UIImage


I have 4 points on an image (not perfectly a rectangle, just a 4 point polygon). For example:

enter image description here

I want to extract the image bounded by the 4 points, resulting image: enter image description here

Using Quartz, I can only specify a rectangle to do this. However, i might not have a perfect rectangle all the time, so what's the best way to do this? Thanks


Solution

  • What about to use OpenGL "Render to texture" technique? Use those 4 points as input texture coordinates and render straight rectangle to the output texture.