簡體   English   中英

在某些情況下顯示從畫廊中選擇的圖像

[英]Show selected images from gallery upon some condition

我的要求是從日期條目中讀取輸入,以搜索特定日期范圍之間的圖像。
到目前為止,我剛剛創建了一個圖庫視圖以從images文件夾中檢索所有圖像。
我的代碼是給定的。

在僅顯示那些滿足條件的圖像之前,如何顯示條件才能顯示圖像文件夾的縮略圖?

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;
}

如果您的意思是文件類型條件,則只需設置所需的文件類型即可。
就像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())
    }  

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM