【发布时间】:2019-04-18 03:26:04
【问题描述】:
我正在尝试制作一个应用程序,用户可以在其中从图库中选择图像并可以将其重命名为所需的名称, 从图库中获取图像的代码是
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMG);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
try {
upload.setVisibility(View.INVISIBLE);
Image.setVisibility(View.VISIBLE);
final Uri imageUri = data.getData();
final InputStream imageStream = getContentResolver().openInputStream(imageUri);
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
Image.setImageBitmap(selectedImage);
Log.i("FileName is", fileName);
} catch (FileNotFoundException e){
e.printStackTrace();
Toast.makeText(getApplicationContext(),"Error Loading Image",Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(),"Please select an image",Toast.LENGTH_LONG).show();
}
}
我看过一些使用from 和to 重命名图像的帖子,但我无法理解它是如何工作的以及如何设置所需的名称(用户将通过editText 输入) .
任何帮助将不胜感激
【问题讨论】:
-
如果图像在同一个文件夹中,你将如何处理重命名?
标签: android imageview file-rename