In order to convert almost any type of image into a PPM I'm using ImageMagick's wand API. From the wand how do I extract the PPM properties of width, height, modval and raw RGB data? Here is some skeleton code.
为了将几乎任何类型的图像转换为PPM,我使用的是ImageMagick的魔杖API。从魔杖如何提取宽度,高度,模态和原始RGB数据的PPM属性?这是一些骨架代码。
Many thanks in advance for reading the question.
非常感谢你提前阅读这个问题。
/* Read an image. */
MagickWandGenesis();
magick_wand = NewMagickWand();
status = MagickReadImage(magick_wand, argv[1]);
if (status == MagickFalse)
ThrowWandException(magick_wand);
/* TODO convert to P6 PPM */
/* TODO get PPM properties */
ppm->width = ...
ppm->height = ...
ppm->modval = 3 * ppm->width;
ppm->data = malloc(ppm->width * ppm->height * 3);
/* TODO fill ppm->data */
1 个解决方案
#1
0
来自ImageMagick论坛
width = MagickGetImageWidth(magick_wand);
height = MagickGetImageHeight(magick_wand);
ppm->width = width;
ppm->height = height;
ppm->modval = 3 * width;
ppm->data = malloc (3 * width * height);
status = MagickExportImagePixels(magick_wand, 0, 0, width, height, "RGB",
CharPixel, ppm->data);
#1
0
来自ImageMagick论坛
width = MagickGetImageWidth(magick_wand);
height = MagickGetImageHeight(magick_wand);
ppm->width = width;
ppm->height = height;
ppm->modval = 3 * width;
ppm->data = malloc (3 * width * height);
status = MagickExportImagePixels(magick_wand, 0, 0, width, height, "RGB",
CharPixel, ppm->data);