在我的应用程序中,我需要捕获一些图像并将它们保存在一个文件夹中,并可以选择重命名它。谢谢你的帮助,抱歉我的英语不好.....我试过但是它不起作用,只保存一张图片甚至拍多张照片,为什么?谢谢: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);
}
});
}
}
答案 0 :(得分: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)
{
}
}
在此功能拍摄照片后,您可以执行某些操作。
还有其他方法可以做到这一点