Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get c buffer from ImageMagick Image

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);
    }
like image 721
Pickles Avatar asked Jul 15 '10 18:07

Pickles


1 Answers

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];
like image 200
Pickles Avatar answered Oct 16 '22 12:10

Pickles