gpt4 book ai didi

iphone - 图像 90 度旋转 AVCam

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:48 26 4
gpt4 key购买 nike

我在 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;
}

最佳答案

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

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

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

关于iphone - 图像 90 度旋转 AVCam,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12512267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com