开发者

Change this tutorial to access images from the sd card?

How would I edit this tutorial so that it will grab images from the SD card?

http://developer.android.com/guide/tutorials/views/hello-gallery.html

          private Integer[] mImageIds = {
        R.drawable.lol.marker,
        R.drawable.sample_2,
        R.drawable.sample_3,
        R.drawable.sample_4,
        R.drawable.sample_5,
        R.drawable.sample_6,
        R.drawable.sample_7
  开发者_StackOverflow中文版      };

Alternatively is it possible to make subfolders within R.drawable?


R.drawable is not a directory but a class containing static fields which are references to your resources.You can't create subfolders in the directory "drawable".
Now If you want to replace this array of ids by images on the SD card, you have to use a content resolver to get them. Would be something like that I suppose :

Cursor c = this.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null,null);
startManagingCursor(c);  

and then when you have retrieved the id of the images you want, you can put them in the array and use something like that to display them :

yourImageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, id+"")); 

EDIT
You can try something like that. Though i'm not sure:

 Bitmap bitmap = BitmapFactory.decodeFile("path/to/the/image.png");
  yourImageView.setImageBitmap(bitmap);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜