IOS ELCImagePicker 从枚举类型 ALAssetOrientation 到不同枚举类型 UIImageOrientation 的隐式转换

标签 ios objective-c elcimagepickercontroller

刚刚下载了 ELCImagePicker,现在我在 ELCImagePickerController.m 中收到此警告

Implicit conversion from enumeration type 'ALAssetOrientation' (aka 'enum ALAssetOrientation) to different enumeration type 'UIImageOrientation' (aka 'UIImageOrientation')

引发警告的代码是:

orientation = [assetRep orientation];

如果更能说明问题,这里是完整的函数:

- (void)selectedAssets:(NSArray *)assets
{
NSMutableArray *returnArray = [[NSMutableArray alloc] init];

for(ELCAsset *elcasset in assets) {
    ALAsset *asset = elcasset.asset;
    id obj = [asset valueForProperty:ALAssetPropertyType];
    if (!obj) {
        continue;
    }
    NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];

    CLLocation* wgs84Location = [asset valueForProperty:ALAssetPropertyLocation];
    if (wgs84Location) {
        [workingDictionary setObject:wgs84Location forKey:ALAssetPropertyLocation];
    }

    [workingDictionary setObject:obj forKey:UIImagePickerControllerMediaType];

    //This method returns nil for assets from a shared photo stream that are not yet available locally. If the asset becomes available in the future, an ALAssetsLibraryChangedNotification notification is posted.
    ALAssetRepresentation *assetRep = [asset defaultRepresentation];

    if(assetRep != nil) {
        if (_returnsImage) {
            CGImageRef imgRef = nil;
            //defaultRepresentation returns image as it appears in photo picker, rotated and sized,
            //so use UIImageOrientationUp when creating our image below.
            UIImageOrientation orientation = UIImageOrientationUp;

            if (_returnsOriginalImage) {
                imgRef = [assetRep fullResolutionImage];
                orientation = [assetRep orientation];
            } else {
                imgRef = [assetRep fullScreenImage];
            }
            UIImage *img = [UIImage imageWithCGImage:imgRef
                                               scale:1.0f
                                         orientation:orientation];
            [workingDictionary setObject:img forKey:UIImagePickerControllerOriginalImage];
        }

        [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:UIImagePickerControllerReferenceURL];

        [returnArray addObject:workingDictionary];
    }

}    
if (_imagePickerDelegate != nil && [_imagePickerDelegate respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)]) {
    [_imagePickerDelegate performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:) withObject:self withObject:returnArray];
} else {
    [self popToRootViewControllerAnimated:NO];
}
}

最佳答案

为了消除此警告,我更新了这段代码:

if (_returnsOriginalImage) {
    imgRef = [assetRep fullResolutionImage];
    orientation = [assetRep orientation];
} else {
    imgRef = [assetRep fullScreenImage];
}

至以下内容:

if (_returnsOriginalImage) {
    imgRef = [assetRep fullResolutionImage];

    NSNumber *orientationValue = [asset valueForProperty:@"ALAssetPropertyOrientation"];
    if (orientationValue != nil) {
        orientation = [orientationValue intValue];
    }

} else {
    imgRef = [assetRep fullScreenImage];
}

关于IOS ELCImagePicker 从枚举类型 ALAssetOrientation 到不同枚举类型 UIImageOrientation 的隐式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26134719/

相关文章:

ios - 从 iOS 上传多张图片到 S3 的有效方法

iphone - Objective c 将字符串对象添加到数组

ios - 我想添加 ELCImagePickerController 并保留选定的图像

objective-c - NSTextView,设置字符串: raising exception

objective-c - 将检测到的矩形从纵向 CIImage 转换为横向 CIImage

ios - 如何使用 ELCImagePickerController 检查所选视频的大小

ios - 在核心数据的库中保存和获取多个图像选择

ios - 在 iOS 7.0.3 中使用 boundingRectWithSize 的 UILabel 渲染问题

ios - NSFetchedResultsControllerDelegate在合并来自另一个上下文的更改后更新表单元格

ios - 枚举数组和枚举字典之间的映射