我已经问过这个问题了,但那是关于FreeImage
。现在我正在尝试做同样的事情ImageMagick
(更正确地说,与Magick++
).
我所需要的只是获取图像中像素的 RGB 值,并能够将其打印到屏幕上。我在ImageMagick
论坛,不过好像没人。 :-( 有人可以帮忙吗?
版本 6 API
给定一个“Image“对象,你必须请求一个”像素缓存“,然后使用它。文档是here and here:
// load an image
Magick::Image image("test.jpg");
int w = image.columns();
int h = image.rows();
// get a "pixel cache" for the entire image
Magick::PixelPacket *pixels = image.getPixels(0, 0, w, h);
// now you can access single pixels like a vector
int row = 0;
int column = 0;
Magick::Color color = pixels[w * row + column];
// if you make changes, don't forget to save them to the underlying image
pixels[0] = Magick::Color(255, 0, 0);
image.syncPixels();
// ...and maybe write the image to file.
image.write("test_modified.jpg");
版本 7 API
版本 7 中对像素的访问发生了变化(请参阅:porting),但低级访问仍然存在:
MagickCore::Quantum *pixels = image.getPixels(0, 0, w, h);
int row = 0;
int column = 0;
unsigned offset = image.channels() * (w * row + column);
pixels[offset + 0] = 255; // red
pixels[offset + 1] = 0; // green
pixels[offset + 2] = 0; // blue
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)