开发者

Rotating a PNG file

开发者 https://www.devze.com 2023-02-20 11:12 出处:网络
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 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":

  1. Create a CGImage from the original file, using ImageIO (CGImageSourceCreateWithURL, CGImageSourceCreateImageAtIndex).
  2. Create a bitmap context with transposed size, using Core Graphics (CGBitmapContextCreate).
  3. Rotate the context's transformation matrix (CGContextConcatCTM)
  4. Draw the original image into that context (CGContextDrawImage).
  5. Create a new image from the bitmap context (CGBitmapContextCreateImage)
  6. Save the image to a new file (CGImageDestinationCreateWithURL, CGImageDestinationAddImage, CGImageDestinationFinalize).


Have you tried looking at NSImage Rotation asked on Stackoverflow?

0

精彩评论

暂无评论...
验证码 换一张
取 消