我想使用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库在旋转过程中会改变输出格式和/或步幅?
致以敬意,
发布于 2014-01-18 10:32:11
CImg不以交错模式存储图像的像素缓冲区,如RGBARGBARGBA.但是使用通道结构RRRRRRRR.....GGGGGGGGG.......BBBBBBBBB.....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.我想这应该会像预期的那样起作用。
https://stackoverflow.com/questions/21202635
复制相似问题