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... のように、チャネルごとにチャネル構造を使用します。ポインターがインターリーブされたチャネルを持つピクセルを指していると想定して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 に答える