9

Androidデベロッパーサイトによると:

Android 2.2以降には機能があります

" setDisplayOrientation "

をクリックして、カメラ プレビューの回転を調整します。

また、Android Developer Site によると、次のソース コードが見つかります。

android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0 ;
    switch ( rotation ) {
        case Surface.ROTATION_0 : degrees = 0 ; break ;
        case Surface.ROTATION_90 : degrees = 90 ; break ;
        case Surface.ROTATION_180 : degrees = 180 ; break ;
        case Surface.ROTATION_270 : degrees = 270 ; break ;
    }
    int result ;
    if ( info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = ( info.orientation + degrees ) % 360 ;
         result = ( 360 - result ) % 360 ;   // compensate the mirror
    } else {   // back-facing

        result = ( info.orientation - degrees + 360 ) % 360 ;

    }

ただし、ある種のデバイスでは動作しません。Samsung Galaxy Y S5360、S5660、YP-G1、YP-G70などのように

Galaxy Nexus、SII、またはハイエンドデバイスの一部が機能していないだけで、正常に機能します。

setDisplayOrientation は をサポートしていませんか、それともデバイスのファームウェアの準備ができていませんか?

PS。すべてのデバイスは Android 2.3.1 以降です。

ヘルプ。

4

2 に答える 2

3

カメラの向き表示を設定する問題は、基本的に (ジンジャーブレッド) であるこれらのデバイスのオペレーティング システム バージョンでは機能しませんが、これより上のデバイスでは正常に機能します。

これらのデバイスでもこれを試してみましたが、横向きモードでは問題なく動作しますが、縦向きモードには問題があります。強制的にポートレートにする場合は、これを介してカメラの向きを 90 度に強制しました。

public void surfaceChanged(SurfaceHolder holder, int format, int width,
    int height) {

camera.setDisplayOrientation(90);


}

同様に、画像を表示または保存する前に画像を回転させました

    PictureCallback myPictureCallback_JPG = new PictureCallback(){


     public void onPictureTaken(byte[] arg0, Camera arg1) {

    Bitmap bitmapPicture= BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
      Matrix matrix = new Matrix();
     matrix.postRotate(90);
     int height=bitmapPicture.getHeight();
     int width=bitmapPicture.getWidth();
     Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmapPicture,height,width, true);
      Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
}

お役に立てれば

于 2013-02-21T06:30:27.687 に答える
-3

カメラ ビューの xml の向きを横向きに設定してみてください。

于 2012-10-05T12:25:29.610 に答える