如何从ImageMagick Image获取c缓冲区 [英] How to get c buffer from ImageMagick Image

查看:156
本文介绍了如何从ImageMagick Image获取c缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这里是代码:

  MagickReadImage(wand,filename); 

while(MagickHasNextImage(wand)){
Image * myImage = GetImageFromMagickWand(wand);
// HELP ME PLEASE
const void * myBuff = myImage-> blob; //猜测这是正确的方式获取缓冲区?
int myLength = //不知道如何获取长度
NSData * myData = [[NSData alloc] initWithBytes:myBuff length:myLength];
UIImage myImage = [[UIImage alloc] initWithData:myData]];
MagickNextImage(wand);
}


解决方案现在我有解决方案:

  size_t my_size; 
unsigned char * my_image = MagickGetImageBlob(wand,& my_size);
NSData * data = [[NSData alloc] initWithBytes:my_image length:my_size];
免费(my_image);

UIImage * image = [[UIImage alloc] initWithData:data];


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

这篇关于如何从ImageMagick Image获取c缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆