gpt4 book ai didi

iphone - 仅将图像保存到自定义相册

转载 作者:可可西里 更新时间:2023-11-01 03:11:40 24 4
gpt4 key购买 nike

我一直在学习本教程 http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/将图像保存到自定义相册。这工作正常,但它保存到相机胶卷和我的自定义相册。

查看代码,这似乎是一个必要的步骤,因为在将图像保存到相机胶卷后,我们有一个 ALAsset 可以与 ALAssetsGroup addAsset: 方法一起使用。

有没有一种方法可以在不将图像添加到相机胶卷的情况下将图像添加到自定义相册?

当前使用此代码:

-(void)saveImage:(UIImage*)image toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{

//write the image data to the assets library (camera roll)
[self writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation
completionBlock:^(NSURL* assetURL, NSError* error) {

//error handling
if (error!=nil) {
completionBlock(error);
return;
}

//add the asset to the custom photo album
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];

}];
}

-(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
__block BOOL albumWasFound = NO;

//search all photo albums in the library
[self enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

//compare the names of the albums
if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {

//target album is found
albumWasFound = YES;

//get a hold of the photo's asset instance
[self assetForURL: assetURL
resultBlock:^(ALAsset *asset) {

//add photo to the target album
[group addAsset: asset];

//run the completion block
completionBlock(nil);

} failureBlock: completionBlock];

//album was found, bail out of the method
return;
}

if (group==nil && albumWasFound==NO) {
//photo albums are over, target album does not exist, thus create it

__weak ALAssetsLibrary* weakSelf = self;

//create new assets album
[self addAssetsGroupAlbumWithName:albumName
resultBlock:^(ALAssetsGroup *group) {

//get the photo's instance
[weakSelf assetForURL: assetURL
resultBlock:^(ALAsset *asset) {

//add photo to the newly created album
[group addAsset: asset];

//call the completion block
completionBlock(nil);

} failureBlock: completionBlock];

} failureBlock: completionBlock];

//should be the last iteration anyway, but just in case
return;
}

} failureBlock: completionBlock];

}

最佳答案

原来没有 - 默认情况下,图像将始终写入相机胶卷。

关于iphone - 仅将图像保存到自定义相册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14113361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com