如何显示来自特定目录的图像,android

问题描述:

在我的画廊我有3个目录。 sahoo是其中的一个目录。我在所有三个目录中都有不同的图像。但我只想显示sahoo目录的图像。我的程序显示了图库中的所有图像。但我只想从sahoo目录中获取图像。怎么做? 我正在使用android。如何显示来自特定目录的图像,android

感谢 迪帕克

我用下面的代码

Uri uri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI; 
Cursor mCursor = this.getContentResolver().query(uri, null, selection, null, null); 

和getview方法我已经写了下面的代码行

mCursor.moveToPosition(position); 
     Log.e(TAG,"the position is"+position); 
     long id = mCursor.getLong(mCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID)); 
//  Log.e(TAG,"the value of id= "+id); 
     //create the Uri for the Image 
     Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id+""); 

     Intent intent = new Intent(Intent.ACTION_VIEW); 

     intent.setData(uri); 

     startActivity(intent); 
+0

是你sahoo目录库的子目录? – RoflcoptrException 2011-03-25 07:59:59

+0

能完成这项工作吗? http://*.com/questions/3490623/is-there-any-way-to-look-for-an-image-using-the-path-mediastore-images-thumbnail – rajath 2011-03-25 08:04:20

+0

是的,它的工作原理。 sahoo目录是库的子目录 – 2011-03-25 09:14:17

你可以从所有图像的路径使用游标。然后检查路径是否与您不想显示图像的路径不匹配,然后存储pathin arraylist。使用setImageURI()方法在ImageView中创建您的owngrid和适配器显示图像。在这种情况下,Donot使用默认画廊。

uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 

      String[] projection = { MediaColumns.DATA, 
        MediaColumns.DISPLAY_NAME }; 

      cursor = activity.managedQuery(uri, projection, null, null, null); 
      column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); 
while (cursor.moveToNext()) { 
String absolutePathOfImage = cursor.getString(column_index); 
} 

感谢 苏尼尔