2014-01-18 42 views
2

我想使用的CIMG庫(http://cimg.sourceforge.net/)以任意角度旋轉的圖像(該圖像由Qt的讀其不應當執行旋轉):CIMG庫創建上旋轉扭曲圖像

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

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. 

我想這應該按預期工作。

+0

感謝您指出這一點! – Hyndrix

+0

注意:置換後,CImg報告的寬度,高度,光譜和深度都將改變!小心不要像我今天那樣浪費時間 – M2X