0

画像を保存するときに「保存した写真」フォルダを無効にする方法はありますか?

NSData *data1 = UIImagePNGRepresentation(imageToCrop.image);
        UIImage *tehnewimage = [UIImage imageWithData: data1];
        [self.library saveImage:tehnewimage toAlbum:@"Databender Edits"     withCompletionBlock:^(NSError *error) {
            if (error!=nil) {
                NSLog(@"eRrOr: %@", [error description]);
            }
        }];
4

1 に答える 1

1

ALAssetsLibrary を使用してアプリの写真を管理している場合、写真は常に保存された写真の下に表示されます。Apple Docsによると、ALAssetsLibraryの目的は

You use it to retrieve the list of all asset groups and to save images and videos into the Saved Photos album.

アプリ内で画像にアクセスするだけでよい場合は、読み取り、書き込み、およびそれらの表示を自分で処理できます。これにより、カメラの役割や保存された写真に表示されなくなります。

 //WRITING TO APP DIRECTORY
 NSString *directory = [NSHomeDirectory() stringByAppendingPathComponent:@"Photos/"];

if (![[NSFileManager defaultManager] fileExistsAtPath:directory]){
    NSError* error;
    [[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&error];
}
NSData *imgData = UIImagePNGRepresentation(imageToCrop.image);
NSString *imgName = @"example.png";
NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:imgName];
[imgData writeToFile:pngPath atomically:YES]; 

//READING FROM APP DIRECTORY
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"/Photos/"] error:NULL];
for (int i = 0; i < (int)[directoryContent count]; i++)
{
    NSURL *url = [NSURL URLWithString:[NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"/Documents/Photos/%@",[directoryContent objectAtIndex:i]]]];
    UIImage *image = [UIImage imageWithContentsOfFile:[url absoluteString]];
    //ADD IMAGE TO TABLE VIEW OR HANDLE HOW YOU WOULD LIKE
}
于 2013-05-23T14:46:41.413 に答える