2010-07-15 35 views
6

我正在使用ImageMagick的iPhone端口。我试图循环遍历动画gif的帧,并将每个帧转换为UIImage。我知道我可以用NSData初始化一个UIImage,我可以用一个const void *来初始化它。那么如何获得图像的缓冲区和长度?如何从ImageMagick获取c缓冲区图像

下面的代码:

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); 
    } 

回答

4

我现在已经解决:

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