1

我对编程很陌生,但这是我的代码。我正在尝试开发一个应用程序,我希望它立即打开相机功能。这就是我正在使用的。它要求我添加更多细节,所以我想我应该输入更多......任何帮助将不胜感激。这是我教得很差的一门课的唯一成绩

import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;


public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback   {
private SurfaceHolder sHolder;
public Camera camera= null;{

}



public CameraSurfaceView(Context context) {
    super(context);
    sHolder= getHolder(); 
    sHolder .addCallback(this);

    // TODO Auto-generated constructor stub
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    // TODO Auto-generated method stub
    Camera.Parameters params= camera.getParameters();
    params.setPreviewSize(width, height);
    camera.setParameters(params);
    camera.startPreview();

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    try{
        camera.setPreviewDisplay(sHolder);
    }catch(Exception e){
    }
    // TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    camera.stopPreview();
    camera= null;   
} 

public void capture (Camera.PictureCallback jpegHandler){
camera.takePicture(null, null, jpegHandler);
}

}
4

0 回答 0