How to load Images from file

All your problems with Audio, Video and Images.

How to load Images from file

Postby bswee » Mon Dec 08, 2008 1:52 am

Hi all, I'm new to Android as well as this site.

Goal: I am trying to create a slide show application and I need to be able to load images from file. Does Android have a 'file choose'? At the very least I am currently trying to load images by simply typing in the file names that are in the res folder.

mBodyText = (EditText) findViewById(R.id.filename); //set file name
InputStream is = getResources().openRawResource(R.drawable.mBodyText ); //this does not work, I can only load images by hard coding the file names in res folder
bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);

If anyone has some comments to either improve this solution or a new approach, please comment. Thanks for your time.
bswee
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 08, 2008 1:35 am

Top

Re: How to load Images from file

Postby Rahul » Mon Dec 15, 2008 11:09 am

you can have a look at this tutorial

gallery_with_remote_images-t769.html

bswee wrote:Hi all, I'm new to Android as well as this site.

Goal: I am trying to create a slide show application and I need to be able to load images from file. Does Android have a 'file choose'? At the very least I am currently trying to load images by simply typing in the file names that are in the res folder.

mBodyText = (EditText) findViewById(R.id.filename); //set file name
InputStream is = getResources().openRawResource(R.drawable.mBodyText ); //this does not work, I can only load images by hard coding the file names in res folder
bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);

If anyone has some comments to either improve this solution or a new approach, please comment. Thanks for your time.
Rahul
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Wed Oct 01, 2008 11:16 am

Postby hebbalhrk » Mon Dec 22, 2008 10:50 am

Probabaly you can use file filter to filter out all the media files of particular format and list them..
say you want to list all audio files on sdcard..

File images = new File("/sdcard/");
if (images.listFiles(new FileFilter()).length > 0) {
for (File file : images.listFiles(new FileFilter())) {
songlist.add(file.getName());
}
ArrayAdapter<String> songList = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, songlist);
setListAdapter(songList);


The file filter class returns files with specified extensions
class FileFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return ((name.endsWith(".mp3")) || (name.endsWith(".wav")));
}
}
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google Feedfetcher and 16 guests