0

在我的应用程序中,我需要捕获一些图像并将它们保存在具有重命名选项的文件夹中。感谢您的帮助,对不起我的英语不好.....我试过了,但它不起作用,它只保存一张图像甚至拍摄更多照片,为什么?感谢:D

public class TestPress extends Activity  {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.prova);
        final String direct = this.getIntent().getStringExtra("key");

        // TODO Auto-generated method stub
        Button p = (Button) findViewById(R.id.button2);
        p.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                Intent camera= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

                Uri uriSavedImage=Uri.fromFile(new File("/sdcard/CameraTest/flashCropped.png"));
                camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                startActivityForResult(camera, 1);

            }
        });
        Button np = (Button) findViewById(R.id.button3);
        np.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent next = new Intent(Press.this, CameraActivity.class);
                startActivity(next);
            }
        });
    }
}
4

1 回答 1

1
    private void doTakePhotoAction() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // 创建目录
    File fileDir = new File(Environment.getExternalStorageDirectory()
            + "/zuijiao");
    if (!fileDir.exists()) {
        fileDir.mkdirs();
    }
    // 拍照后的路径
    imagePath = Environment.getExternalStorageDirectory() + "/zuijiao/"
            + System.currentTimeMillis() + ".jpg";
    carmeraFile = new File(imagePath);
    imageCarmeraUri = Uri.fromFile(carmeraFile);

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
            imageCarmeraUri);

    try {
        intent.putExtra("return-data", true);
        startActivityForResult(intent, ACTION_TAKE_CARMERA);
    } catch (ActivityNotFoundException e) {
        // Do nothing for now
    }
}

并请检查保存文件的长度,如果长度等于0,你应该删除它(有些人打开相机但不拍照,会有一个空文件,删除它)

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == ACTION_TAKE_CARMERA) 
    {

    }
}

您可以在此功能中拍照后做一些事情。

还有其他方法可以做到这一点

于 2013-08-20T00:27:58.813 回答