私はこのチュートリアルに従うカスタムカメラアプリケーションを書いている: http://marakana.com/forums/android/examples/39.htmlAndroidのカスタムカメラの結果画像の向き
今、私は、ユーザーがボタンをクリックした後、カメラを使用して画像データを取得することができますよ。 しかし、私はプレビューが大丈夫だったsurfaceCreated
@Override
public void surfaceCreated(SurfaceHolder holder) {
// Open the camera when the preview is created
Log.d("Callback", "[surfaceCreated]");
theCamera = Camera.open();
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int displayRotation = display.getRotation();
switch (displayRotation) {
case Surface.ROTATION_0: theCamera.setDisplayOrientation(90); break;
case Surface.ROTATION_90: break;
case Surface.ROTATION_180: break;
case Surface.ROTATION_270: theCamera.setDisplayOrientation(180); break;
}
}
に次のコードを追加しますので、プレビューが横向きで問題を得ました。 しかし、画像データを取得したときは、BitmapFactory.decodeByteArray
を使用してビットマップを取得し、これをmy xmlレイアウトで定義されたmy imageViewに設定します。ここで
は私のmain.xml
<SurfaceView
android:id="@+id/previewSurfaceView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="250px" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Button" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="250px" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Button" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
</LinearLayout>
previewSurfaceViewは私がクリックしたときにカメラのプレビューのために
、ボタン1とボタンがボタンであることを小さな図であります、カメラは画像をキャプチャし、imageView1/imageView2に対応する画像データを設定する
いくつかの問題があります。
私はfitCenterにも、スケールタイプを100dpするために、レイアウトの幅と高さを設定しても、最大の幅と高さ。しかし、それは私が望むものとして表示されないようです。私はイメージが境界内のショーであることを望みます。レイアウト設定で間違っているのですか?
画像はポートレートモードで撮影しても常に横長です。
はほかに、私はカメラのオン/オフを切り替えるためのボタンを追加したいが、私はこれを行う方法を見つけ出すことはできません。
誰かが私に解決策を提案できますか?ありがとうございました。
申し訳ありませんが、上記の間違ったコードを投稿しました。私は表面的には問題ありません。しかし、どのようにイメージデータの向きを得ることができます。 – Hanon