0

私はこのメソッドを使用して、MagickWand API を使用してピクセルをエクスポートしています。

MagickExportImagePixels

しかし、これは画像の向きのexifデータに従っていないようです。正しい向きでピクセルを抽出する方法はありますか?別の形式で書き出すことができます(使用しないでMagickWriteImageください)? 基本的に、convert の auto-orient オプションの動作が必要です。

ありがとう!

4

3 に答える 3

1

ImageMagick の 6.8.9 以降のリリースがMagickAutoOrientImage()利用できない場合、次のコードを使用して画像の向きを自動調整します。

void auto_orient_image(MagickWand* image) {
  PixelWand* pwand=0;
  switch(MagickGetImageOrientation(image))
  {
    case UndefinedOrientation:
    case TopLeftOrientation:
    default:
      break;
    case TopRightOrientation:
      MagickFlopImage(image);
      break;
    case BottomRightOrientation:
      pwand=NewPixelWand();
      MagickRotateImage(image, pwand, 180.0);
    case BottomLeftOrientation:
      MagickFlipImage(image);
      break;
    case LeftTopOrientation:
      MagickTransposeImage(image);
      break;
    case RightTopOrientation:
      pwand=NewPixelWand();
      MagickRotateImage(image, pwand, 90.0);
      break;
    case RightBottomOrientation:
      MagickTransverseImage(image);
      break;
    case LeftBottomOrientation:
      pwand=NewPixelWand();
      MagickRotateImage(image, pwand, 270.0);
      break;
  }
  if (pwand) DestroyPixelWand(pwand);
  MagickSetImageOrientation(image, TopLeftOrientation);
}

エラー処理を追加する必要があるかもしれません。

于 2015-01-21T21:30:20.443 に答える
0

これを行う唯一の方法は、画像の向きを取得し、それに応じて画像を回転させることによる疑似手動のようです。難しいことではありませんが、より簡潔なソリューションが API に組み込まれることを望んでいました。不完全な例を次に示します。

OrientationType t = MagickGetImageOrientation(magick_wand);
if (t == RightTopOrientation) {
    MagickRotateImage(mw, pw, 90);
}
...
于 2014-10-03T13:55:25.967 に答える