CImg 库在旋转时创建失真的图像
CImg library creates distorted images on rotation
我想使用 CImg 库 (http://cimg.sourceforge.net/) 以任意角度旋转图像(图像由 Qt 读取,不应执行旋转):
QImage img("sample_with_alpha.png");
img = img.convertToFormat(QImage::Format_ARGB32);
float angle = 45;
cimg_library::CImg<uint8_t> src(img.bits(), img.width(), img.height(), 1, 4);
cimg_library::CImg<uint8_t> out = src.get_rotate(angle);
// Further processing:
// Data: out.data(), out.width(), out.height(), Stride: out.width() * 4
当角度设置为 0 时,"out.data()" 中的最终数据是可以的。但对于其他角度,输出数据会失真。我假设 CImg 库在旋转过程中更改了输出格式和/或步幅?
问候
CImg 不会以交错模式存储图像的像素缓冲区,因为 RGBARGBARGBA...但使用逐通道结构RRRRRRRRRR.....嘎��嘭��啊我假设您的img.bits()
指针指向具有交错通道的像素,因此如果要将其传递给 CImg,则需要在应用任何 CImg 方法之前排列缓冲区结构。试试这个:
cimg_library::CImg<uint8_t> src(img.bits(), 4,img.width(), img.height(), 1);
src.permute_axes("yzcx");
cimg_library::CImg<uint8_t> out = src.get_rotate(angle);
// Here, the out image should be OK, try displaying it with out.display();
// But you still need to go back to an interleaved image pointer if you want to
// get it back in Qt.
out.permute_axes("cxyz"); // Do the inverse permutation.
const uint8_t *p_out = out.data(); // Interleaved result.
我想这应该按预期工作。
相关文章:
- 在决定是通过参考还是通过价值时,尺寸真的是一个问题吗
- 旋转模型矩阵时的形状失真
- 字节真的是最小可寻址单元吗
- 如果我真的真的想从 STL 容器继承,并且我继承构造函数并删除新运算符,会发生什么?
- 如何在 std::vector 中找到<bool>哪些索引是真的?
- std::string 的对象真的可以移动吗?
- 在这种情况下,我真的复制了字节还是复制了字符?
- int8_t和uint8_t真的是整数吗?它们有什么用?
- 真的没有来自 std::string_view 的 std::string 的显式构造函数吗?
- 查找不等式为真的次数时出现问题
- 考虑到其他好处,关键字'auto'真的有助于简化调试C++吗?
- 有没有更好的方法来处理异常? try-catch块真的很丑
- 在为嵌套类定义行外友元时,我真的必须打破封装吗?
- 你如何理解"std: :forward is just syntactic sugar"?这是真的吗?
- "std::forward"和"std::move"真的不生成代码吗?
- 鱼眼镜头校准给出失真矩阵零
- VS 2017 和 2019 运行 c++ 真的很慢
- 结构和类在C++中真的等价吗?
- CP1251:从字符* 转换为 wchar_t* 时的编码失真
- 指向数组unique_ptr在调用 release() 后会自动释放动态内存,这是真的吗?