Objective-C/ALAssetLibrary - How read and save informations about images

Hieicker

I have found some informations about images inside my emulator using the ALAssetLibrary. I can show correctly these informations using the NSLog, but i don't know how can i save these informations inside a list for example. The code i'm using is this:

NSMutableArray *list = [[NSMutableArray alloc] init];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
        [group setAssetsFilter:[ALAssetsFilter allPhotos]];
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
            if (asset){
                NSString *description = [asset description];
                NSRange first = [description rangeOfString:@"URLs:"];
                NSRange second = [description rangeOfString:@"?id="];
                NSString *path = [description substringWithRange: NSMakeRange(first.location + first.length, second.location - (first.location + first.length))];
                NSLog(@"Path: %@", path);
                [list addObject:path];
                NSDictionary *data = [[asset defaultRepresentation] metadata];
                NSNumber *width = [[[asset defaultRepresentation] metadata] objectForKey:@"PixelWidth"];
                NSString *widthString = [NSString stringWithFormat:@"%@", width];
            }
        }];
    }
} failureBlock:^(NSError *error) {
    NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];
NSLog(@"LIST: %@", list);

For what i'm understanding, these operations works asynchronously, so i don't know how can i save them. Any idea?

Thanks

Hieicker

At the end i have resolved the problem using this code:

NSMutableArray *idList = [[NSMutableArray alloc] init];
NSMutableArray *widthList = [[NSMutableArray alloc] init];
NSMutableArray *heightList = [[NSMutableArray alloc] init];
NSMutableArray *orientationList = [[NSMutableArray alloc] init];
NSMutableArray *dateList = [[NSMutableArray alloc] init];

__block ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block NSString *description = [[NSString alloc] init];

[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
        [group setAssetsFilter:[ALAssetsFilter allPhotos]];
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
            if (asset){
                NSString *description = [asset description];
                NSLog(@"description %@", description);
                NSRange first = [description rangeOfString:@"URLs:"];
                NSRange second = [description rangeOfString:@"?id="];
                NSString *path = [description substringWithRange: NSMakeRange(first.location + first.length, second.location - (first.location + first.length))];
                [idList addObject:path];

                NSDictionary *data = [[asset defaultRepresentation] metadata];

                NSNumber *width = [[[asset defaultRepresentation] metadata] objectForKey:@"PixelWidth"];
                NSString *widthString = [NSString stringWithFormat:@"%@", width];
                [widthList addObject:widthString];

                NSNumber *height = [[[asset defaultRepresentation] metadata] objectForKey:@"PixelHeight"];
                NSString *heightString = [NSString stringWithFormat:@"%@", height];
                [heightList addObject:heightString];

                NSNumber *orientation = [[[asset defaultRepresentation] metadata] objectForKey:@"Orientation"];
                NSString *orientationString = [NSString stringWithFormat:@"%@", orientation];
                if(orientationString != NULL){
                    [orientationList addObject:orientationString];
                } else {
                    NSString *noOrientation = [[NSString alloc] init];
                    noOrientation = @"No orientation avaiable";
                    [dateList addObject:noOrientation];
                }

                NSString *dateString = [[[asset defaultRepresentation] metadata] objectForKey:@"DateTime"];
                if(dateString != NULL){
                    [dateList addObject:dateString];
                } else {
                    NSString *noDate = [[NSString alloc] init];
                    noDate = @"No date avaiable";
                    [dateList addObject:noDate];
                }
            }
        }];
    }
    if (group == nil){
        XMLWriter* xmlWriter = [[XMLWriter alloc]init];
        [xmlWriter writeStartDocumentWithEncodingAndVersion:@"UTF-8" version:@"1.0"];
        [xmlWriter writeStartElement:@"Data"];
        int i = 0;
        for(i = 0; i<=[idList count]-1; i++){
            NSLog(@"width: %@", [widthList objectAtIndex:i]);
            [xmlWriter writeStartElement:@"Photo"];
            [xmlWriter writeAttribute:@"Id" value:[idList objectAtIndex:i]];
            [xmlWriter writeAttribute:@"Width" value:[widthList objectAtIndex:i]];
            [xmlWriter writeAttribute:@"Height" value:[heightList objectAtIndex:i]];
            [xmlWriter writeAttribute:@"Orientation" value:[orientationList objectAtIndex:i]];
            [xmlWriter writeAttribute:@"Date" value:[dateList objectAtIndex:i]];
            [xmlWriter writeEndElement:@"Photo"];
        }
        [xmlWriter writeEndElement:@"Data"];
        [xmlWriter writeEndDocument];
        NSString* xml = [xmlWriter toString];
        NSLog(@"XML: %@", xml);
    }

} failureBlock:^(NSError *error) {
    NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];

In this mode i have also wrote the informations how an xml using an Xml Stream Writer (https://github.com/skjolber/xswi). Hope that this will help.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Objective-C / ALAssetsLibrary - Find images informations and Exif informations

From Dev

how to get informations about relationship of tables in oracle?

From Dev

How to get more informations about this device?

From Dev

How to read images in android

From Dev

How can I save and read variable size images in TensorFlow's protobuf format

From Dev

how to save taken images to use as background images?

From Dev

How to cache images in Objective-C

From Dev

How to cache images in Objective-C

From Dev

How to retrieve informations about journals from ISI Web of Knowledge?

From Dev

How to preserve informations about original observable on RxJava2

From Dev

How to design an Info-Screen filled with detailed informations about an object

From Dev

How to save the position of the audio file? objective -C

From Dev

Objective c - How save text style with SQLite?

From Dev

Corrupted images when using Read and Write streams to save files

From Dev

Read images from sub folders and save into another folder

From Dev

How to read an untrusted certificate to extract informations using Python?

From Dev

how to read reply SMS in objective-c

From Dev

How to read a file without extension in Objective C

From Dev

How do I save plot images in R?

From Dev

How to save an "Images.xcassets" file

From Dev

How to save images into specific folder in iOS 9.0

From Dev

How to save images from imageView to SD

From Dev

How to save images in sRGB color profile

From Dev

how to save multi images by MEL command

From Dev

How to save images from server and reuse later

From Dev

How to save images during debugging the code in opencv?

From Dev

How to save images on ftp server or sql db?

From Dev

how to save the generated images from this code separated

From Dev

How to save duplicate images in Excel to different JPEGs

Related Related

  1. 1

    Objective-C / ALAssetsLibrary - Find images informations and Exif informations

  2. 2

    how to get informations about relationship of tables in oracle?

  3. 3

    How to get more informations about this device?

  4. 4

    How to read images in android

  5. 5

    How can I save and read variable size images in TensorFlow's protobuf format

  6. 6

    how to save taken images to use as background images?

  7. 7

    How to cache images in Objective-C

  8. 8

    How to cache images in Objective-C

  9. 9

    How to retrieve informations about journals from ISI Web of Knowledge?

  10. 10

    How to preserve informations about original observable on RxJava2

  11. 11

    How to design an Info-Screen filled with detailed informations about an object

  12. 12

    How to save the position of the audio file? objective -C

  13. 13

    Objective c - How save text style with SQLite?

  14. 14

    Corrupted images when using Read and Write streams to save files

  15. 15

    Read images from sub folders and save into another folder

  16. 16

    How to read an untrusted certificate to extract informations using Python?

  17. 17

    how to read reply SMS in objective-c

  18. 18

    How to read a file without extension in Objective C

  19. 19

    How do I save plot images in R?

  20. 20

    How to save an "Images.xcassets" file

  21. 21

    How to save images into specific folder in iOS 9.0

  22. 22

    How to save images from imageView to SD

  23. 23

    How to save images in sRGB color profile

  24. 24

    how to save multi images by MEL command

  25. 25

    How to save images from server and reuse later

  26. 26

    How to save images during debugging the code in opencv?

  27. 27

    How to save images on ftp server or sql db?

  28. 28

    how to save the generated images from this code separated

  29. 29

    How to save duplicate images in Excel to different JPEGs

HotTag

Archive