0
나는 안드로이드 시스템에서 활동을 개발했으며 런타임에 문제가 있습니다 : 활동을 시작할 때 "D/카메라 : 응용 프로그램이 NULL 표면을 통과했습니다"라는 메시지가 표시되고 표면보기에 카메라의 이미지. SurfaceHolder 객체의 'isValid'함수에 대한 코드를 코드에 삽입하고 함수는 false를 반환합니다.안드로이드 표면이 유효하지 않습니다
이것은 활동 코드입니다.
package marl.com.mbpspay;
import android.hardware.Camera;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CameraActivity extends AppCompatActivity implements SurfaceHolder.Callback {
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
try{
camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
}catch(RuntimeException e){
Log.e("CameraActivity", "init_camera: " + e);
return;
}
if(surfaceHolder.getSurface().isValid()) {
Log.i("PreviewCallback", "Camera open [" + surfaceHolder + "]");
}
Camera.Parameters param;
param = camera.getParameters();
//modify parameter
param.setPreviewFrameRate(20);
param.setPreviewSize(176, 144);
camera.setParameters(param);
Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Log.i("PreviewCallback","image get");
}
};
try {
Log.i("PreviewCallback","STEP 0 ["+surfaceHolder.getSurface()+"]");
camera.setPreviewDisplay(surfaceHolder);
Log.i("PreviewCallback","STEP 1 ["+surfaceHolder+"]");
camera.setPreviewCallback(previewCallback);
Log.i("PreviewCallback","STEP 2 ["+surfaceHolder+"]");
camera.startPreview();
//camera.takePicture(shutter, raw, jpeg)
} catch (Exception e) {
Log.e("CameraActivity", "init_camera: " + e);
return;
}
}
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
여기 레이아웃의 xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="marl.com.mbpspay.CameraActivity">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/surfaceView" />
</RelativeLayout>
누군가이 문제의 해결책을 찾을 수 있습니까?