gpt4 book ai didi

iphone - 从 ALAssset 检索时的 CGImage 方向问题

转载 作者:行者123 更新时间:2023-12-03 19:33:21 25 4
gpt4 key购买 nike

我刚刚开始学习 iPhone 应用程序开发。我正在尝试使用 ALAsset 类从我的相册中检索照片并将照片上传到我的服务器。然而,在人像模式下拍摄的照片向左旋转90度,而风景照片则正确上传。我究竟做错了什么?在 NSLog 中,我确实看到方向为 3,但照片仍然向左旋转 90 度。任何帮助将不胜感激。

这是我的代码片段:

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

imagePath = [[documentsDirectory stringByAppendingPathComponent:@"latest_photo.jpg"] copy];
NSLog(@"imagePath = %@", imagePath);

ALAssetRepresentation *rep = [myasset defaultRepresentation];
ALAssetOrientation orientation = [rep orientation];
NSLog(@"Orientation = %d", orientation);

CGImageRef iref = [rep fullResolutionImage];

if (iref) {
UIImage *largeimage = [UIImage imageWithCGImage:iref scale:1.0 orientation:orientation];
NSData *webData = UIImageJPEGRepresentation(largeimage,0.5);

[webData writeToFile:imagePath atomically:YES];

// Upload the image

最佳答案

对于代码的 Assets 导向部分,而不是

ALAssetRepresentation *rep = [myasset defaultRepresentation];
ALAssetOrientation orientation = [rep orientation];

尝试

ALAssetOrientation orientation = [[asset valueForProperty:@"ALAssetPropertyOrientation"] intValue];

关于iphone - 从 ALAssset 检索时的 CGImage 方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6312231/

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