【问题标题】:iOS 13 - Saving UIImage with wrong orientation [duplicate]iOS 13 - 以错误的方向保存 UIImage [重复]
【发布时间】:2019-12-07 21:32:47
【问题描述】:

我在照片的方向上遇到了一些问题。 拍摄肖像照片并将其保存到相机胶卷后,我看到它旋转了。但是当我将它添加到图像视图时,它看起来还不错。 其他人发现了同样的问题吗?反馈助手中是否存在未解决的错误? 谢谢!

当我尝试使用 PHPhotoLibrary 保存它时发生了同样的问题

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); //Saves rotated
    imageView.image = image; //Appears OK
    [self dismissModalViewControllerAnimated:YES];
}
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
assetPlaceholder = changeRequest.placeholderForCreatedAsset;

【问题讨论】:

    标签: ios objective-c uiimage uiimagepickercontroller phphotolibrary


    【解决方案1】:

    我的项目中有这个扩展。试试看。

    extension UIImage {
        func fixOrientation() -> UIImage {
            if imageOrientation == .up {
                return self
            }
            UIGraphicsBeginImageContextWithOptions(size, false, scale)
            draw(in: CGRect(origin: .zero, size: size))
            let normalizedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() ?? self
            UIGraphicsEndImageContext()
            return normalizedImage
        }
    }
    

    【讨论】:

    • 1.这个问题被标记为 Objective-C,而不是 Swift。请以适当的语言发布答案。 2.请不要发布仅代码的答案。一个好的答案可以解释问题中的问题,并解释了答案如何解决问题。
    猜你喜欢
    • 2011-12-11
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多