【发布时间】:2017-05-14 19:38:01
【问题描述】:
我正在使用 React Native 构建一个应用程序,我需要使用照片 uri(例如 photos://A2B9B28B-9A3E-4190-BCA0-B11F1E587085/L0/002)从照片库中以 base64 格式获取图像。我最初使用的是资产库,但我更新了我的应用以使用新的照片库,但我正在努力让它工作。
我的旧资产库方法是:
{
NSURL *url = [[NSURL alloc] initWithString:input];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:url resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
CGImageRef imageRef = [rep fullScreenImage];
NSData *imageData = UIImagePNGRepresentation([UIImage imageWithCGImage:imageRef]);
NSString *base64Encoded = [imageData base64EncodedStringWithOptions:0];
callback(@[[NSNull null], base64Encoded]);
} failureBlock:^(NSError *error) {
NSLog(@"that didn't work %@", error);
callback(@[error]);
}];
}
【问题讨论】:
-
获取图片后可以转base 64
-
只需要解决
photos://A2B9B28B-9A3E-4190-BCA0-B11F1E587085/L0/002到NSData的转换即可; base64 的东西无关紧要且令人困惑 -
你是如何获得
photos://A2B9B28B-9A3E-4190-BCA0-B11F1E587085/L0/002的? -
来自github.com/olofd/react-native-photos-framework。正如我在帖子中所说,我使用的是 React Native,所以目标是将 Javascript 中的图像作为 base64;所以我不确定你是怎么觉得它不相关或令人困惑的。
标签: ios objective-c react-native