我正在使用ImageMagick的iPhone端口。我试图循环动画gif的帧并将每个帧转换为UIImage。我知道我可以用NSData初始化一个UIImage,我可以使用const void *初始化。那么如何获得图像的缓冲区和长度呢?
以下是代码:
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);
}
答案 0 :(得分: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];