每个 body ,
好吧,实际上我正在从我的相册中拍照。我正在画它,然后当我完成时,我将它保存到我的相册中。它工作得很好。问题当然是当我保存这个新图像时,设备将它保存到另一个图像中。我想知道的是,是否可以修改现有图像?喜欢替换它来创建一个新的?或者如果不可能,我可以删除库中的图像并创建一个新图像吗?
完美的方法是使用 URL。
// I take the image
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:asseturl
resultBlock:^(ALAsset *asset){NSLog(@"I got my image");}
failureBlock:^(NSError *error){NSLog(@"Error");}];
//然后我用一个新的替换它
???
先感谢您
最佳答案
非常感谢组合,没有你我永远找不到它。
因此,代码仅在应用程序创建 Assets 时才有效。这是方法:
- (void)replaceImageWithUrl:(NSString *)url withImage:(UIImage*)image
{
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
NSURL *asseturl = [NSURL URLWithString:url];
[assetLibrary assetForURL:asseturl
resultBlock:^(ALAsset *asset)
{
ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];
NSLog(@"Image name : %@",assetRepresentation.filename);
if([asset isEditable])
{
NSLog(@"Asset editable");
[asset setImageData:UIImageJPEGRepresentation(image, 1.0) metadata:asset.defaultRepresentation.metadata completionBlock:^(NSURL *assetURL, NSError *error)
{
if (error)
NSLog(@"error %@",error);
else
NSLog(@"assetURL %@", assetURL);
}];
}
else
{
NSLog(@"Not editable");
}
}
failureBlock:^(NSError *error){NSLog(@"FAILED");
}];
}
似乎删除了以前的图像并使用新名称创建了一个新图像,它没有优化但它可以工作......
关于objective-c - 替换相册照片中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12959506/