gpt4 book ai didi

android - 获取从android中的图库中选择的图像的图像名称

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:27:36 27 4
gpt4 key购买 nike

我已经从图库中浏览了图像并将其设置为 ImageView 现在我需要获取已在 ImageView 中设置的图像的图像名称。我在下面附上了我的代码。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("req","req"+requestCode);
Log.d("res","res"+resultCode);

if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imageView = (ImageView) findViewById(R.id.imgView);

imageView1 = (ImageView) findViewById(R.id.imgView1);

if(browse == 1){
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
if(browse == 2){
imageView1.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
String resName = getResources().getResourceEntryName(R.id.imgView);
Toast.makeText(getApplicationContext(), "BBB"+resName,Toast.LENGTH_LONG).show();

}

最佳答案

试试这个 how to get file name from URI

File f = new File(picturePath);
String imageName = f.getName();

关于android - 获取从android中的图库中选择的图像的图像名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23777027/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com