jcrowson
jcrowson

Reputation: 4290

Image asset path from Core Data into PNG

I'm storing the file location in the asset library of photos taken using the camera in my core data graph to avoid having a huge database and memory problems.

For example:

assets-library://asset/asset.JPG?id=2F62642E-00B3-4D85-82D2-A6A1F064F2CE&ext=JPG

I'm now creating a pdf file that displays these images in a nice table, however I have no idea how to convert the asset path to a usable UIImage and represent it as a PNG.

Upvotes: 0

Views: 582

Answers (1)

lxt
lxt

Reputation: 31304

You need to use the ALAssetsLibrary to retrieve the corresponding asset, with the assetForURL:resultBlock:failureBlock: method. This will return either the ALAsset object (which you can then use to obtain an image), or an error.

It's very important that you handle the errors gracefully, because the asset URLs can and do change: either through user actions (e.g, the user has deleted the asset and it's no longer available) or through something else (iOS updates can invalidate asset URLs).

Upvotes: 3

Related Questions