开发者

Change save place of the custom camera application

开发者 https://www.devze.com 2023-03-04 01:50 出处:网络
Here is my code, this thing work fine. Right now the pictures were saved in the same folder as the mobile camera but I want to change the save location to another folder. Any suggestion?

Here is my code, this thing work fine. Right now the pictures were saved in the same folder as the mobile camera but I want to change the save location to another folder. Any suggestion?

SurfaceView cameraView;
SurfaceHolder surfaceHolder;
Camera camera;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentView(R.layout.main);

    cameraView = (SurfaceView)this.findViewById(R.id.CameraView);
    surfaceHolder = cameraView.getHolder();
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    surfaceHolder.addCallback(this);

    cameraView.setFocusable(true);
    cameraView.setFocusableInTouchMode(true);
    cameraView.setClickable(true);

    cameraView.setOnClickListener(this);
}
public void onClick(View v){
    camera.takePicture(null, null, this);
}

@Override
public void onPictureTaken(byte[] data, Camera camera) {
    Uri imageFileUri =开发者_如何学JAVA getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
    try{
        OutputStream imageFileOS = getContentResolver().openOutputStream(imageFileUri);
        imageFileOS.write(data);
        imageFileOS.flush();
        imageFileOS.close();
    } catch(FileNotFoundException e){
        Toast t = Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
        t.show();
    } catch (IOException e) {
        Toast t = Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
        t.show();
    }
    camera.startPreview();
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
    camera.startPreview();
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    try{
        camera.setPreviewDisplay(holder);
        Camera.Parameters parameters = camera.getParameters();
        parameters.setPictureSize(640, 480);
        camera.setParameters(parameters);
    } catch(IOException e){
        camera.release();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    camera.stopPreview();
    camera.release();
}


Right, you need to change Uri imageFileUri (or OutputStream imageFileOS). Where do you want to store image file?

0

精彩评论

暂无评论...
验证码 换一张
取 消