【问题标题】:Image 90 degrees rotated AVCam图像 90 度旋转 AVCam
【发布时间】:2012-09-20 12:07:36
【问题描述】:

我在 Stackoverflow 中查看了大量问题,但没有一个能解决我的问题。

所以,我正在使用 Apple 的 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;
}

【问题讨论】:

  • stackoverflow.com/questions/5427656/… 看起来很有希望。
  • 该链接中的解决方案有效,但它会导致您再次渲染整个图像,这需要一段时间,尤其是相机胶卷中的大图像。请参阅我的答案。

标签: iphone ios gpuimage avcam


【解决方案1】:

当您裁剪图像时,您会丢失与该图像关联的元数据,告诉它旋转它的正确方法。

相反,您的代码应该像这样保留图像的原始旋转:

- (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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多