本文介绍了检索Android中特定文件夹的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我创建了GridView来显示特定文件夹中的图像.问题是我想从DCIM/100ANDRO文件夹中检索图像.应通过查询传递哪种类型的参数以检索此类图像?请为我提供解决方案.

In my application I created the GridView to show the image from particular folder.The issue is that I want to retrieve images from the DCIM/100ANDRO folder.Which type of arguments should be passed through query to retrieve such type of images?Please provide me solution.

我正在使用以下代码进行检索,从而获得相机捕获的图像

I am using following code to retrieve which gives me images captured by camera

        //importing only camera images and storing in ArrayList of class Images     type
        String[] projection = {
        MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
        MediaStore.Images.Media.DISPLAY_NAME
        };
        String selection = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " = ?";
        String[] selectionArgs = new String[] {
            "Camera"
        };

        Cursor mImageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null );

        if (mImageCursor != null)
        {

            mImageCursor.moveToFirst();

            for (int i = 0; i < mImageCursor.getCount(); i++)
            {
                Images im=new Images();
                eachImageView=new ImageView(this);
                int imageId = mImageCursor.getInt((mImageCursor.getColumnIndex( MediaStore.Images.Media._ID)));
                Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
                    imageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
                im.setBitmap(bm);
                eachImageView.setImageBitmap(bm);
                im.setImageView(eachImageView);

                arrayOfImages.add(im);

                mImageCursor.moveToNext();
            }
        }

建议将不胜感激!

推荐答案

File folder = new File(Environment.getExternalStorageDirectory().toString() + "/Folder Name/");
folder.mkdirs();
File[] allFiles = folder.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png"));
    }
});

这篇关于检索Android中特定文件夹的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:59