I have zero experience with manipulating image files of any sort with code, so I am lost about where to begin. All I need to do is open a PNG image file and save it rotated 90 degrees in objective-C. I am a quick learner, so even a push in the right direction would help immensely. I know this is no obscure function; any GUI image editor is capable of this, so I figure someo开发者_JAVA百科ne should be able to help. Thanks in advance!
(also, I have tagged this with iPhone to get more exposure; this is not something that needs to be iPhone-exclusive.)
Here's your "push":
- Create a
CGImage
from the original file, using ImageIO (CGImageSourceCreateWithURL
,CGImageSourceCreateImageAtIndex
). - Create a bitmap context with transposed size, using Core Graphics (
CGBitmapContextCreate
). - Rotate the context's transformation matrix (
CGContextConcatCTM
) - Draw the original image into that context (
CGContextDrawImage
). - Create a new image from the bitmap context (
CGBitmapContextCreateImage
) - Save the image to a new file (
CGImageDestinationCreateWithURL
,CGImageDestinationAddImage
,CGImageDestinationFinalize
).
Have you tried looking at NSImage Rotation asked on Stackoverflow?
精彩评论