3

iPhone で画像の向きを正しく設定するのに問題があります。AssetLibrary クラスを使用して画像にアクセスしています。

私がやりたいのは、表示用に画像を適切に配置することだけです。残念ながら、ポートレートモードで撮影された一部の画像では、意味をなさない方向になっています。

フレームワークによって呼び出されるブロックでは、iPhone のカメラが「上」を向いている間に撮影された写真に対して、次の呼び出しを行っています。

        ALAssetRepresentation   *representation = [myasset defaultRepresentation];
        ALAssetOrientation      orient          = [representation orientation];
        ALAssetOrientation      alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue];
        UIImage                 *timg           = [[UIImage alloc] initWithCGImage:[representation fullScreenImage]];
        UIImageOrientation      imgorient       = [timg imageOrientation];

THe variable orient = ALAssetOrientationRight.
The variable alorient = ALAssetOrientationUp.
The variable imgorient = UIImageOrientationUp

私は向きの値を使用して画像を回転させ、「上」に見えるようにしました。残念ながら、横向きモードで撮影した画像がある場合、向きが正しくないため、同じコードは機能しません。

scale:orientation: オーバーロードを使用して、方向パラメーターに orient を使用して timg をインスタンス化しようとしましたが、方向を設定する画像を初期化するだけで、画像が正しく回転しません。

これは決定論的ではないように思えますが、これらの呼び出しが異なる結果を返す理由は次のとおりです。

ALAssetOrientation      orient   = [representation orientation];
ALAssetOrientation      alorient = [[myasset valueForProperty:@"ALAssetOrientation"] intValue];

どうぞよろしくお願いいたします。

ありがとう、ウィル

4

1 に答える 1

0

問題は、間違ったプロパティ名を使用したことです。

あなたのコードで:

[[myasset valueForProperty:@"ALAssetOrientation"] intValue];

次のようにする必要があります。

[[myasset valueForProperty:@"ALAssetPropertyOrientation"] intValue];

のドキュメントによると、-[ALAsset valueForProperty:]

If property is not a valid key, returns ALErrorInvalidProperty.

ALErrorInvalidPropertyあなたのコードは intにキャストしようとしましたが、結果は0. 偶然ALAssetOrientationUpにも の値が0あるため、alorient変数は常に に評価されALAssetOrientationUpます。

于 2013-01-29T08:22:20.943 に答える