0

I'm using AVCaptureDevice to capture image from camera. After setting up session, and capturing image, I can get a NSData * and a NSDictionary * object, however, due to the separation of EXIF meta and data, when I tried to convert the NSData * to UIImage *, and put it in a UIImageView *, the image is misoriented.

I know I can use a lot of fix methods to get the image right, and I'm doing it right now, but the thing is, when the image resolution is high (ie, 3000 * 4000), the fix method is slow, it takes around 500 milliseconds on my iPhone5. After running time profiler with instruments, the major time is spent on writing data, which is inevitable I guess.

So I'm wondering am I doing the right thing? Shouldn't there be a easier yet more efficient way to solve the problem like this? Please help me out of here, big thanks!

Void Main
  • 2,241
  • 3
  • 27
  • 36

1 Answers1

1

This is possible without actually rotating the image bytes by using the ImageIO framework. You want to create an image destination with CGImageDestinationCreateWithURL, then add your image data along with its EXIF data with CGImageDestinationAddImage.

There are a couple of examples floating around on SO, like this one.

If all you want to do is display this image, then you can create a UIImage with a specified rotation from the data using:

+ (UIImage *)imageWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation
Community
  • 1
  • 1
Tark
  • 5,153
  • 3
  • 24
  • 23
  • Thanks Tark, the method you mentioned needs to save the image to a file, right? What if I don't want to save it, I just want to display it within a UIImageView ? – Void Main Dec 05 '13 at 08:01
  • In that case, all you need to do is to create a UIImage from the data specifying the rotation given in the EXIF metadata. I updated the answer with the method you should be looking at. – Tark Dec 05 '13 at 20:08
  • Guess that's what is takes. Thank you for your help! – Void Main Dec 06 '13 at 01:03