开发者

ALAssetRepresentation as NSData for GIFs

开发者 https://www.devze.com 2023-01-17 09:29 出处:网络
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 libr

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

  1. a way to grab the NSData straight from an ALAssetRepresent开发者_如何学运维ation object or

  2. a 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消