I'm try to allow users to pull images out of their Photos collections using ALAssetsLibrary
. Users can then upload these images. My goal is to allow users to upload any GIFs they may have in their library w/o loosing any animation they may have.
For PNG and JPEG files I can grab the ALAssetRepresentation
, use - (CGImageRef)fullResolutionImage
to get a CGImageRef
, and then save it to NSData using UIImageJPEGRepresentation
or UIImagePNGRepresentation
.
However, because no similar function exists for GIF files, all I can do is covert the GIF to either JPEG or PNG, but then I lose the animation.
Is there either
a way to grab the NSData straight from an
ALAssetRepresent开发者_如何学运维ation
object ora way to go from
ALAssetRepresentation
->CGImageRef
->NSData
without loosing any gif animation frames?
Thanks in advance!
Yes, there is a quite simple way:
Use the getBytes:fromOffset:length:error: method of ALAssetRepresentation. This gives youthe raw file data of the ALAsset, in your case the GIF file.
精彩评论