Disappearing Thumbnails

169 Views Asked by At

In my application I've noticed the images I'm saving are begin written to a photo album and display properly in the Photos application. However, when I removed the image from which the new image was copied, the new image's thumbnail disappears. It's really strange.

Here's the code I use to create a CGImageRef to save to the assets library:

NSDictionary *options = [NSDictionary
    dictionaryWithObjectsAndKeys:(__bridge NSNumber *)kCFBooleanTrue,
            (__bridge NSString *)kCGImageSourceCreateThumbnailFromImageAlways, nil];
CGImageRef fullImage = [asset.defaultRepresentation CGImageWithOptions:options];

Before I was just grabbing the defaultRepresentation.fullResolution image and writing it to the assets library.

My question is: By saving the image this way, is the thumbnail I expect being created? And, if not, should I do something different to get my thumbnails to be created so they don't "disappear".

EDIT: The error in the console when this occurs is:

Aug 18 11:08:27 [phone name] [app name][2081] <Error>: Fixing thumbnail for 0x112b2dc0 <x-coredata://97C87589-EC35-4664-BE0D-AD01687EF7C4/Asset/p3637> AF6CD736-EF5D-482A-AFAD-F12834C301BF at index 2

The failed thumbnail repair seems occurs only for images where I'm modifying the GPS dictionary with new coordinates. Images where I remove the coordinates have the thumbnails repaired correctly.

Here's my code for that section:

NSDictionary *gpsDictionary =
    [readOnlyMetadata valueForKey:(__bridge NSString*) kCGImagePropertyGPSDictionary];
NSMutableDictionary *modifiableGpsDictionary = (gpsDictionary) ?
    [gpsDictionary mutableCopy] : [[NSMutableDictionary alloc] init];
        CLLocationCoordinate2D coordinate = thumbnail.coordinate;

[modifiableGpsDictionary setValue:[NSNumber numberWithDouble:ABS(coordinate.latitude)]
    forKey:(__bridge NSString*) kCGImagePropertyGPSLatitude];
[modifiableGpsDictionary setValue:(coordinate.latitude < 0.0) ? @"S" : @"N"
    forKey:(__bridge NSString*) kCGImagePropertyGPSLatitudeRef];
[modifiableGpsDictionary setValue:[NSNumber numberWithDouble:ABS(coordinate.longitude)]
    forKey:(__bridge NSString*) kCGImagePropertyGPSLongitude];
[modifiableGpsDictionary setValue:(coordinate.longitude < 0.0) ? @"W" : @"E"
    forKey:(__bridge NSString*) kCGImagePropertyGPSLongitudeRef];

[modifiableMetadata setValue:modifiableGpsDictionary
    forKey:(__bridge NSString*) kCGImagePropertyGPSDictionary];
1

There are 1 best solutions below

0
On

Turns out the way I was adding GPS data to images without an existing dictionary is the problem:

Saving Geotag info with photo on iOS4.1