AVDでは利用できるようです。実機では試していません。
別に特別な事は必要ありませんでした。
以外に簡単でした。
package com.android.camera2; import java.util.List; import android.app.Activity; import android.hardware.Camera; import android.os.Bundle; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; public class Android2CameraActivity extends Activity { private Camera camera; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SurfaceView mySurfaceView = (SurfaceView) findViewById(R.id.surfaceView1); SurfaceHolder holder = mySurfaceView.getHolder(); holder.addCallback(mSurfaceListener); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); SurfaceView mySurfaceView2 = (SurfaceView) findViewById(R.id.surfaceView2); SurfaceHolder holder2 = mySurfaceView2.getHolder(); holder2.addCallback(mSurfaceListener2); holder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // カメラの総数 int numberOfCameras = Camera.getNumberOfCameras(); Log.d("個数", String.valueOf(numberOfCameras)); } private SurfaceHolder.Callback mSurfaceListener = new SurfaceHolder.Callback() { public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(0); try { camera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); Log.d("エラー", "001" ); } } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.release(); camera = null; } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub Log.d("サーフェイスサイズ", "w=" + String.valueOf(width) + "h=" + height);// 320x180 camera.stopPreview(); // camera.setDisplayOrientation(90);// カメラを回転 Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> size = parameters.getSupportedPreviewSizes(); Log.d("カメラのサイズ", "w=" + String.valueOf(size.get(0).width) + "h=" + String.valueOf(size.get(0).height));// parameters.setPreviewSize(size.get(0).width, size.get(0).height); camera.setParameters(parameters); camera.startPreview(); } }; /* * */ private SurfaceHolder.Callback mSurfaceListener2 = new SurfaceHolder.Callback() { public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(1); try { camera.setPreviewDisplay(holder); } catch (Exception e) { e.printStackTrace(); Log.d("エラー", "001" ); } } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.release(); camera = null; } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub Log.d("サーフェイスサイズ", "w=" + String.valueOf(width) + "h=" + height); camera.stopPreview(); // camera.setDisplayOrientation(90);// カメラを回転 Camera.Parameters parameters = camera.getParameters(); List<Camera.Size> size = parameters.getSupportedPreviewSizes(); Log.d("カメラのサイズ", "w=" + String.valueOf(size.get(0).width) + "h=" + String.valueOf(size.get(0).height));// parameters.setPreviewSize(size.get(0).width, size.get(0).height); camera.setParameters(parameters); camera.startPreview(); } }; }
0 件のコメント:
コメントを投稿