首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IOS ELCImagePicker从枚举类型ALAssetOrientation到不同枚举类型UIImageOrientation的隐式转换

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

Stack Overflow用户
提问于 2014-10-01 05:33:17
回答 1查看 1.2K关注 0票数 2

刚刚下载了ELCImagePicker,我现在在ELCImagePickerController.m中得到这个警告。

代码语言:javascript
复制
Implicit conversion from enumeration type 'ALAssetOrientation' (aka 'enum ALAssetOrientation) to different enumeration type 'UIImageOrientation' (aka 'UIImageOrientation')

抛出警告的代码是:

代码语言:javascript
复制
orientation = [assetRep orientation];

这是一个完整的功能,如果更能说明问题的话:

代码语言:javascript
复制
- (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];
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-22 05:48:24

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

代码语言:javascript
复制
if (_returnsOriginalImage) {
    imgRef = [assetRep fullResolutionImage];
    orientation = [assetRep orientation];
} else {
    imgRef = [assetRep fullScreenImage];
}

以下各点:

代码语言:javascript
复制
if (_returnsOriginalImage) {
    imgRef = [assetRep fullResolutionImage];

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

} else {
    imgRef = [assetRep fullScreenImage];
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26134719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档