相同ALAssetsLibrary资产的不同图像?

时间:2015-07-24 23:23:15

标签: ios uiimagepickercontroller alassetslibrary alasset cgbitmapcontext

我使用以下命令从ALAssetsLibrary获取图像:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

信息词典中的图片格式为kCGImageAlphaNoneSkipLastkCGBitmapByteOrderDefault

稍后,例如,当重新启动应用时,我使用referenceURL来获取相同的图片。这次的格式为kCGImageAlphaNoneSkipFirstkCGBitmapByteOrder32Little

通常情况下,这似乎不是问题,因为UIImage由UIImageView和其他UIKit方法正确处理。但是,我还将此图像发送到GLView,在选择器图像的情况下,由于所有蓝色和红色值都已交换,所以最终会出现错误的色调(我可以通过交换R和B字节来纠正它)。

我不知道这是一个错误还是我做错了什么。如果有人能告诉我为什么会这样,以及解决方法是什么,我会很感激。

以下是我用来获取图像的两种方法中的每一种的代码:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:referenceURL resultBlock:^(ALAsset *anAsset) {
    CGImageRef cgImage = anAsset.defaultRepresentation.fullResolutionImage;
    CGBitmapInfo info = CGImageGetBitmapInfo(cgImage);
    int alphaInfo = info & kCGBitmapAlphaInfoMask;
    int byteInfo = (info & kCGBitmapByteOrderMask) >> 12;
    CGImageAlphaInfo otherAlpheInfo = CGImageGetAlphaInfo(originalImage.CGImage);

// I'm seeing:
// alphaInfo:  6 (kCGImageAlphaNoneSkipFirst)
// byteInfo:   2 (kCGBitmapByteOrder32Little)
// otherAlphaInfo: 6 (kCGImageAlphaNoneSkipFirst)

} failureBlock:^(NSError *error) {
    originalImage = nil;
    thumbnail = nil;
}];

使用- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info方法:

mediaURL = info[@"UIImagePickerControllerMediaURL"];
referenceURL = info[@"UIImagePickerControllerReferenceURL"];
originalImage = info[UIImagePickerControllerOriginalImage];
if (originalImage) {
        CGBitmapInfo info = CGImageGetBitmapInfo(originalImage.CGImage);
        int alphaInfo = info & kCGBitmapAlphaInfoMask;
        int byteInfo = (info & kCGBitmapByteOrderMask) >> 12;
        CGImageAlphaInfo otherAlpheInfo = CGImageGetAlphaInfo(originalImage.CGImage);
// I'm seeing:
// alphaInfo:  5 (kCGImageAlphaNoneSkipLast)
// byteInfo:   0 (kCGBitmapByteOrderDefault)
// otherAlphaInfo: 5 (kCGImageAlphaNoneSkipLast)
}

0 个答案:

没有答案