读书人

怎么调用系统相机拍摄图片保存在指定文

发布时间: 2013-06-19 10:26:41 作者: rapoo

如何调用系统相机拍摄图片保存在指定文件夹
如题,我想实现用户点击按钮调用相机,拍照后将刚拍的照片,按指定的名称保存在指定的文件夹中,请问要怎样实现啊?我自己写的代码如下,就是不能保存在我指定的文件夹中,而是以默认名称保存在默认的文件夹下,求解。
在线等,有答案马上结贴,谢谢了!


//拍照获取图片,点击拍照调用此方法
protected void doTakePhoto() {
try {
PHOTO_DIR.mkdirs();// 创建照片的存储目录
mCurrentPhotoFile = new File(PHOTO_DIR, getPhotoFileName());// 给新照的照片文件命名
final Intent intent = getTakePickIntent(mCurrentPhotoFile);
startActivityForResult(intent, CAMERA_WITH_DATA);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "e=" + e, Toast.LENGTH_LONG).show();
}
}

public static Intent getTakePickIntent(File f) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
Uri u = Uri.fromFile(f);
intent.putExtra(MediaStore.EXTRA_OUTPUT, u);
return intent;
}
//用当前时间给取得的图片命名
private String getPhotoFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat(
"'IMG'_yyyy-MM-dd_HH:mm:ss");
return dateFormat.format(date) + ".jpg";
}

[解决办法]
要分么,嘎嘎

[解决办法]
LZ能把你的完全代码给我看下的么,邮箱dz.simple@gmail.com 谢了哈
[解决办法]
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File path = new File(mstrPath);
if(!path.exists())
path.mkdirs();
mstrFileName = Global.GetTime2() + ".jpg";
mstrFilePath = mstrPath + "/" + mstrFileName;
Log.e(Global.TAG, mstrFilePath);
File file = new File(mstrFilePath);
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, 1);

哈哈,随便回个,方便你结贴哈
[解决办法]
上面的代码只是创建了路径跟文件名,但是并没有写数据呀。。。

读书人网 >Android

热点推荐