안녕하세요. 그동안 여러분들 도움으로 프로젝트가 많이 진척이 나갔답니다!
하지만 역시나 배우고 배워도 오류나는 이 상황 ㅜ.ㅜ
이번에는 카메라 어플인데요.
에뮬레이터에서 처음에는 작동을 잘하는데 문제가 여기서 가로모드로 전환하면 에러가 생겨버립니다.
아래 소스 첨부 했구요. 설명좀 부탁드릴께요 !!
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.FrameLayout;
import com.Forgo3.R;
public class Note extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.note);
final CameraSurfaceView cameraView = new CameraSurfaceView(getApplicationContext());
FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
//this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
frame.addView(cameraView);
}
private class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera camera = null;
public CameraSurfaceView(Context context) {
super(context);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Parameters params = camera.getParameters();
params.setPreviewSize(width, height);
params.set("orientation", "portrait");
// params.setPreviewFormat(format);
camera.setParameters(params);
camera.startPreview();
}
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try {
camera.setPreviewDisplay(mHolder);
} catch (Exception e) {
Log.e("Camera", "Failed to set camera preview display", e);
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera = null;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/noteCam" android:text="카메라"
android:textSize="10px" android:layout_width="80dp"
android:layout_height="50dp" />
<FrameLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/frame" />
</LinearLayout>
전 참고로 세로모드만 보기를 원합니다. 메니페스트에서 portait로 해도 에러가 자꾸 나네요 ㅜ.ㅜ