我想使用 CImg 库(http://cimg.sourceforge.net/ 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 库在旋转期间更改输出格式和/或步幅?
Regards,
CImg 不会以交错模式存储图像的像素缓冲区,如 RGBARGBARGBA...,而是使用逐通道结构 RRRRRRRR.....GGGGGGGGGG.......BBBBBBBBBB.....AAAAAAAAA。
我假设你的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.
我想这应该按预期工作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)