【发布时间】:2015-10-23 09:36:18
【问题描述】:
我有一个 ImageMagick++ 图像,我想缩放到我喜欢的任何宽度和高度,然后我想访问这个新缩放图像的像素。
我希望缩放操作永久改变图像。到目前为止,有四种 ImageMagick++ 方法听起来像是可以实现这种缩放操作:resize()、sample()、scale() 和 transform(),但我几乎可以使用的唯一一种方法是 sample()。
问题是当我调用 tMyImage.sample() 然后读取像素值时,图像仅缩放到我传递给它的高度,然后根据原始纵横比设置宽度。
这是我正在使用的代码:
Magick::Image tMyIMage(iOriginalWidth, iOriginalHeight, "BGRA", Magick::CharPixel, (void *)pSourceData);
try { tImage.sample(Magick::Geometry(200, 50, 0, 0)); }
catch { Magick::Exception &eException)
{
// This never happens...
}
tImage.modifyImage();
size_t nNewWidth = tImage.columns();
size_t nNewHeight = tImage.rows();
// At this point I would expect that nNewWidth is 200 and nNewHeight is 50
// Instead, nNewHeight is 50 but nNewWidth is scaled according to the original aspect ratio
// Note here that tImage.baseColumns() and tImage.baseRows() both return 0
tImage.type(Magick::TrueColorType);
const Magick::PixelPacket *pPixels = tImage.getConstPixels(0, 0, nNewWidth, nNewHeight);
// Here I would expect that pPixels points to pixel data of a 200x50 pixel image
我是 ImageMagick++ 的新手,所以我确定我一定做错了什么。任何帮助是极大的赞赏!谢谢!
【问题讨论】:
-
tImage宽度和高度将返回 0,因为您已将像素导入tMyIMage。
标签: c++ image ubuntu imagemagick