0

I am getting such kind of URL for pictures on my iPad:

assets-library://asset/asset.JPG?id=00000000-0000-0000-0000-000000000BC4&ext=JPG

How can I read binary the content of the picture ?
Opening the file with, for example, stringFromFileAtURL gives me that path is not found.

Thanks.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89

2 Answers2

2

You are not allowed to read stuff from there as you please, because it is outside your app's sandbox.

This is not going to be as simple as you want it to be. First you must get the actual image file. This involves getting an ALAsset object (you can see this process in this question. Then, you get that asset's defaultRepresentation and then you get the representation's fullResolutionImage. Then you have a CGImageRef, and you can get is data provider via CGImageGetDataProvider and then a copy of the pixel data via CGDataProviderCopyData which is a CFDataRef (you can cast it to NSData *).

Do you really need the binary? Or is a UIImage good enough? Not sure of your intent with this.

Community
  • 1
  • 1
borrrden
  • 33,256
  • 8
  • 74
  • 109
  • Well, this will get the data from a picture. Not sure how to do it with a movie, but I assume the process would be similar. – borrrden Jul 29 '12 at 08:55
  • You are right, I just found it. Get the representation from AssetLibrary, export it to a Bytes array [rep getbytes...] and copy the bytes to an NSData that can then be transferred. Thanks ! – Laurent Crivello Jul 29 '12 at 11:33
0

It is not necessary to use the assets library, UIImage is the binary representation. If all you want to do is save the image as a file use

[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];

deleted_user
  • 3,817
  • 1
  • 18
  • 27