gpt4 book ai didi

java - 如何从文件中获取图像和图像名称?

转载 作者:行者123 更新时间:2023-12-01 16:56:40 26 4
gpt4 key购买 nike

我为片段选项卡设置了以下代码。我正在尝试从文件中获取图像及其名称并添加到单独的数组列表中。我成功获取图像,但无法获取各自的名称。每次光标都为空。我能做什么?

 public void imageList()
{
File imagePathForImage = new File(Environment.getExternalStorageDirectory());
imageList = imageReader(imagePathForImage);

if(imageList.size() != 0)
{
gallery.setAdapter(new imageAdapater());
gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent openImage = new Intent(getActivity(), FullImageActivity.class);
openImage.putExtra("Img :", imageList.get(i).toString());
startActivity(openImage);
}
});
}
else
{
Toast.makeText(getActivity(), "No image Found", Toast.LENGTH_SHORT).show();
}
}


public void imageNameList ()
{
imageNameList = new ArrayList<String>();
File imagePathForName = new File(Environment.getExternalStorageDirectory() );
Cursor cursor = getContext().getContentResolver().query(Uri.fromFile(imagePathForName), null, null, null, null);
if (cursor == null)
{
Toast.makeText(getActivity(), "No Image File Found", Toast.LENGTH_SHORT).show();
} else
{
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME);
imageNameList.add(cursor.getString(idx));
Log.i( "FineName: " , cursor.getString(idx) );
cursor.close();
}
}

我的计划是创建图像库,在其下面显示各自的名称。

最佳答案

你可以从路径获取

String filename=path.substring(path.lastIndexOf("/")+1);

关于java - 如何从文件中获取图像和图像名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61577499/

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