重命名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;
}
}
}