views:

19

answers:

1

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);
    }
+1  A: 

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];
Pickles