如何在Ubuntu上永久缩放imagemagick++图像
How to permanently scale an ImageMagick++ image on Ubuntu?
我有一个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++,所以我确信我一定是做错了什么。任何帮助都非常感谢!谢谢!
我发现了缩放不工作的原因;显然,imagemagick++的默认设置是,如果最终的宽高比会发生变化,则不会采用您正在使用的确切尺寸在创建几何图形时,必须显式地告诉imagemagick++使用精确的尺寸:
char szGeometry[64];
memset(&(szGeometry[0]), 0, sizeof(szGeometry));
snprintf(szGeometry, sizeof(szGeometry) - 1, "%ix%i!", iWidth, iHeight);
Magick::Image tScaled(iOriginalWidth, iOriginalHeight, "BGRA", Magick::CharPixel, (void *)pSourceData);
try { tScaled.sample(Magick::Geometry(szGeometry)); }
catch (Magick::Exception &eException)
{
...
}
相关文章:
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- 计算缩放多边形的比例,得到给定的多边形面积
- QwtPlot具有相等的轴和自动缩放
- 如何在directx/c++中进行平移/缩放操作
- 在Qt中实现无限可缩放的画布
- 是否可以为 QPixmap 派生类嵌入缩放方法?
- 形状对象的旋转和缩放不正确C++
- 如何在 OpenSceneGraph 中缩放/旋转/移动资产
- 如何在OpenGL(GLFW,很高兴)中进行2D缩放?
- 改变或缩放两个正态分布以具有特定的相关系数
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- 如何在OpenGL中正确旋转和缩放对象?
- 仅当类型为 std::complex 时,才进行缩放
- 将 VS Code 用于跨平台可缩放C++项目
- 根据帧速率缩放/缩小数字
- 在 c++ 中缩放浮点值
- 如何防止 DirectX C++程序的拉伸/缩放
- 使用提升几何缓冲区缩放多边形时的冗余折点
- 为什么我不能使用 Sphere 来缩放字形?
- 如何在Ubuntu上永久缩放imagemagick++图像