Bending bitmap images - just like in PS5. Algorithms? Code? image processing?
Starting with a bitmap image ..
Is there a 开发者_如何转开发trivial way to do this in cocoa I don't know about? (Like "CAShapeLayer for images!")?
The easy way (which is certainly worth considering if you’re targeting a phone) is to use a grid deformation: deform a grid of squares/triangles and texture map your picture onto it. This is easily hardware-accelerated with OpenGL ES. The geometry can be as finely-meshed as you want, but the limited quality of texture sampling may be an issue depending on your application.
The concept is simple, even if the implementation is not.
- Define a mathematical mapping from a position in the output image to a position in the input image. This is probably the hard part, since you're likely to have a formula going from input to output rather than vice versa.
- For each pixel of the output image, determine its coordinates in the input. These will likely have some fractional component, i.e. they won't line up exactly with the input.
- Use the interpolation algorithm of your choice to determine what the value should be at the input point you've chosen.
- Rinse and repeat.
精彩评论