2012-09-20 188 views
2

我已经看了很多问题在这里在Stackoverflow和他们都没有解决我的问题。图片90度旋转AVCam

所以,我使用的是苹果的AVCam样本: http://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html

所以,当我拍张照片,并将其保存在图片库中它的罚款,但是当我表现出来的画面通过裁剪它,当我发送它到服务器通过使用

NSData* pictureData = UIImageJPEGRepresentation(self.snappedPictureView.image, 0.9); 

它发送90度旋转!

这里是我的代码裁剪:

UIImage* cropped = [image imageByCroppingRect:CGRectMake(0, 0, (image.size.width *    300)/self.view.frame.size.width, (image.size.height * 300)/self.view.frame.size.height)]; 


imageByCroppingRect is: 
- (UIImage *) imageByCroppingRect:(CGRect)area 
{ 
UIImage *croppedImage; 
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], area); 
// or use the UIImage wherever you like 
croppedImage = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef); 

return croppedImage; 
} 
+0

http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload外观向我承诺。 –

+0

该链接的解决方案有效,但它会导致您再次渲染整个图像,这需要一段时间,尤其是从摄像机滚动的大图像。请参阅我的回答。 – brynbodayle

回答

2

当你裁剪图像,你正在失去与图片告诉它旋转它的正确方法相关的元数据。

而不是你的代码应该保持图像的原始方向是这样的:

- (UIImage *) imageByCroppingRect:(CGRect)rect { 

    CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect); 
    UIImage *result = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation]; 
    CGImageRelease(imageRef); 
    return result; 
} 
+0

工作!谢谢! –