重命名SD卡上拍摄的照片我用从下面的链接代码,是非常有益的,谢谢: http://www.tutorialforandroid.com/2010/10/take-picture-in-android-with.html保存/ Android中
需要一些照片的问题帮助! takePhoto()启动MediaStore.ACTION_IMAGE_CAPTURE,getFile()创建“Image Keeper”目录,然后在“Image-SOMENUMBER.jpg”名称下保存拍摄的图片在onActivityResult()中我想将拍摄的图片显示为ImageView,喜欢将图片重命名为用户在edittext或其他内容中的输入内容!
有两个问题:
1)为什么我不能得到的ImageView表明我在尝试{}部分图片?我究竟做错了什么?我怎样才能获得保存图像的路径?
2)是否有办法可以让用户命名的照片,他们希望的方式?(类似“另存为”或重命名上的一些按钮点击等。)
任何想法是值得欢迎的!谢谢!
这里是代码:
private static final int TAKE_PHOTO_CODE = 1;
private void takePhoto(){
final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getFile(this)));
startActivityForResult(intent, TAKE_PHOTO_CODE);
}
private File getFile(Context context){
final File path = new File(Environment.getExternalStorageDirectory(), "Image keeper");
if(!path.exists()){
path.mkdir();
}
String name;
int n = 100000;
int rand;
rand = new Random().nextInt(n);
name = "Image-" + rand + ".jpg";
File file = new File(path,name);
return file;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch(requestCode){
case TAKE_PHOTO_CODE:
final File file = getFile(this);
try {
Bitmap captureBmp;
captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(file));
iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageBitmap(captureBmp);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}