0

Does anyone know how to save an image to the Asset Library? I know that saving it to the Asset, the image will be available also in the Gallery of the iPad.

I know how to get the file:

AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:downloadRequest];

[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

// How to make the filepath? 
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation.responseData writeToFile:filePath atomically:YES];
}
gdm
  • 7,647
  • 3
  • 41
  • 71

1 Answers1

0

In order to write an image into the assets library, you can use any of the three methods below (defined in class ALAssetsLibrary):

– writeImageToSavedPhotosAlbum:orientation:completionBlock:
– writeImageDataToSavedPhotosAlbum:metadata:completionBlock:
– writeImageToSavedPhotosAlbum:metadata:completionBlock:

This requires that your image is either represented as a UIImage, a CGImageRef or a NSData object.

For example, you might save your image using a NSOutputStream associated to a temporary file. Then, create and initialize a UIImage with that file and write it into the assets library using the above method.

Alternatively, load the image as a NSData object (if it fits nicely into memory) and again use the appropriate method above, along with meta information.

See also: ALAssetsLibrary Class Reference

Edit:

If you want to get more information about how to setup the metadata parameter, you may find this blog post valuable: Adding metadata to iOS images the easy way.

And if you want to add Geolocations to your image metadata on SO: Saving Geotag info with photo on iOS4.1

Community
  • 1
  • 1
CouchDeveloper
  • 18,174
  • 3
  • 45
  • 67
  • Good question ;) The AV Foundation is more specific about "metadata", but in AL it's quite obscure. You may take a look into sample file "SquareCamViewController.m" in the Apple sample "SquareCam" and try to deduce some conclusion what it *might* be. – CouchDeveloper Jan 04 '14 at 11:00
  • Uhm, it should be clear that the meta data of an image is commonly known as "EXIF" data (Exchangeable Image file Format). But I don't know how to setup the keys and values for the Dictionary representing the metadata. See also wiki article about EXIF: [Exchangeable image file format](http://en.wikipedia.org/wiki/Exchangeable_image_file_format) – CouchDeveloper Jan 04 '14 at 11:20
  • Ah, after digging for "EXIF" in the Apple docs, you may find valuable info for "EXIF Dictionary Keys" in "CGImageProperties Reference". – CouchDeveloper Jan 04 '14 at 11:26