在某些条件下显示从图库中选择的图像

发布于 2024-11-30 12:37:01 字数 1723 浏览 0 评论 0原文

我的要求是从日期条目中读取输入以搜索特定日期范围内的图像。
到目前为止,我刚刚创建了一个图库视图来检索图像文件夹中的所有图像。
我的代码是给定的。

如何在仅显示满足条件的图像的图像文件夹的缩略图之前创建条件?

public void image_search(String st)
{
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,
    "Select Picture"), SELECT_PICTURE);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();

            //OI FILE Manager
            filemanagerstring = selectedImageUri.getPath();

            //MEDIA GALLERY
            selectedImagePath = getPath(selectedImageUri);

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + selectedImagePath), "image/*");
            startActivity(intent);
        }
    }
}

//UPDATED!
public String getPath(Uri uri) {
    String selectedImagePath;
    //1:MEDIA GALLERY --- query from MediaStore.Images.Media.DATA
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if(cursor != null){
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        selectedImagePath = cursor.getString(column_index);
    }else{
        selectedImagePath = null;
    }

    if(selectedImagePath == null){
        //2:OI FILE Manager --- call method: uri.getPath()
        selectedImagePath = uri.getPath();
    }
    return selectedImagePath;
}

My requirement is to read an input from a date entry to search images between specific date range.
So far I have just created a gallery view to retrieve all images from the images folder.
The code I have is as given.

How do I create conditions before displaying the thumbnails of the image folder for only those images which satisfy condition?

public void image_search(String st)
{
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,
    "Select Picture"), SELECT_PICTURE);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();

            //OI FILE Manager
            filemanagerstring = selectedImageUri.getPath();

            //MEDIA GALLERY
            selectedImagePath = getPath(selectedImageUri);

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + selectedImagePath), "image/*");
            startActivity(intent);
        }
    }
}

//UPDATED!
public String getPath(Uri uri) {
    String selectedImagePath;
    //1:MEDIA GALLERY --- query from MediaStore.Images.Media.DATA
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if(cursor != null){
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        selectedImagePath = cursor.getString(column_index);
    }else{
        selectedImagePath = null;
    }

    if(selectedImagePath == null){
        //2:OI FILE Manager --- call method: uri.getPath()
        selectedImagePath = uri.getPath();
    }
    return selectedImagePath;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静待花开 2024-12-07 12:37:01

如果您指的是文件类型条件,那么您可以简单地设置您想要的文件类型。
就像
intent.setType("image/png"); 仅获取 PNG 图像。

编辑:

您应该实现FileFilter接口来获取满足您的条件的列表文件。您可以从此列表中创建缩略图。

File imagesDir = // the File obj of directory containing image files.  
File[] imagelist = imagesDir.listFiles( new FileFilter {

    @override  
    public boolean accept(File file)  
    {  
    // return true if this file meets ur conditions(file.length and file.lastmodified())
    }  

}

If you mean filetype condition then you can simply set filetype you want.
Like
intent.setType("image/png"); to fetch only PNG images.

Edit:

You should implement the FileFilter interface to get the list files satisfying your conditions. You can create thumnails out of this list.

File imagesDir = // the File obj of directory containing image files.  
File[] imagelist = imagesDir.listFiles( new FileFilter {

    @override  
    public boolean accept(File file)  
    {  
    // return true if this file meets ur conditions(file.length and file.lastmodified())
    }  

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文