2

我想使用 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 库会在旋转期间更改输出格式和/或步幅?

问候,

4

1 回答 1

4

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.

我想这应该按预期工作。

于 2014-01-18T10:32:11.347 回答