1

我正在尝试将图像保存到相机胶卷。这实际上工作得很好,但我不得不处理其他东西,现在我要返回项目为 iOS 6 更新它,并且这个功能在iOS6上不再有效。

我尝试了两种方法,没有 NSError 对象,两种方法都静默失败。一、UIImageWriteToSavedPhotosAlbum:

UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

// Callback
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    // error == nil
}

...和 ​​ALAssetsLibrary 方法:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[img CGImage]
                          orientation:(ALAssetOrientation)[img imageOrientation]
                      completionBlock:^(NSURL *assetURL, NSError *error)
{
    // assetURL == nil
    // error == nil
}

此外,[ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized评估为真

在模拟器上,该应用程序从未出现在“设置”>“隐私”>“照片”部分,但在实际的 iPad 上,它们确实显示该应用程序有权访问照片。(另外,补充一点:上面的第一种方法是我以前使用的——它适用于真实设备和模拟器,没问题)。

我也尝试在主线程上运行它,看看是否改变了任何东西 - 没有区别。我之前在后台运行它,它曾经可以正常工作(在模拟器和设备上)。

任何人都可以解释一下吗?

4

1 回答 1

0

想通了...我在做一些愚蠢的事情。UIImage 无法获取原始像素数据,您必须先将其处理成它可以接受的形式,并使用适当的元数据。

部分问题是我使用 Cocos2D 从 CCRenderTexture (getUIImageFromBuffer()) 获取 UIImage,当我切换到 Cocos2D-x 时,该功能不再可用,我只是不知道 UIImage 对象不能用原始像素数据构建,我认为它会自动处理标题信息和格式。

这个答案有帮助:iPhone - UIImage imageWithData 返回 nil

这个例子也很有帮助: http ://www.wmdeveloper.com/2010/09/create-bitmap-graphics-context-on.html?m=1

于 2012-11-15T19:06:47.553 回答