I'm using the iPhone port of ImageMagick. I'm trying to loop through the frames of an animated gif and turn each frame into an UIImage. I know I can init a UIImage with NSData which I can init with a const void *. So how to I get the buffer and length of the image?
Here's the code:
MagickReadImage(wand, filename);
while(MagickHasNextImage(wand)) {
Image *myImage = GetImageFromMagickWand(wand);
//HELP ME PLEASE
const void *myBuff =myImage->blob; //guessing this is the right way to get the buffer?
int myLength = ????? //no idea how to get the length
NSData *myData = [[NSData alloc] initWithBytes:myBuff length:myLength];
UIImage myImage = [[UIImage alloc] initWithData:myData]];
MagickNextImage(wand);
}
I have the solution now:
size_t my_size;
unsigned char * my_image = MagickGetImageBlob(wand, &my_size);
NSData * data = [[NSData alloc] initWithBytes:my_image length:my_size];
free(my_image);
UIImage * image = [[UIImage alloc] initWithData:data];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With