Skip to main content
GameDev.net gamedev.net
🔒 Locked

Android Image Loading

Started by styuR Apr 30, 2012 at 4:06 AM 2 replies 3.2k views
Original Post
styuR
styuR
I'm having issues with the way that I'm loading my images in Android, this is the way I'm doing it just now.


try{
AssetManager assetManager = context.getAssets();
inputStream = assetManager.open("blackcat.png");
cat = BitmapFactory.decodeStream(inputStream);
inputStream.close();

inputStream = assetManager.open("Jellyfish1.png");
jellyfish = BitmapFactory.decodeStream(inputStream);
inputStream.close();

inputStream = assetManager.open("/Dog.png");
bigdog = BitmapFactory.decodeStream(inputStream);
inputStream.close();

inputStream = assetManager.open("exit.png");
exitTile = BitmapFactory.decodeStream(inputStream);
inputStream.close();

inputStream = assetManager.open("kitchen.png");
background = BitmapFactory.decodeStream(inputStream);
inputStream.close();

inputStream = assetManager.open("endscreen.png");
gameover = BitmapFactory.decodeStream(inputStream);
inputStream.close();
}catch(IOException ex){}


Any help would be massively appreciated as I'm pretty stuck for what to do now.
Zael
Zael
Is there any reason you are loading them from assets instead of resources? As I recall loading them from resources is slightly easier.
styuR
styuR
Nope, no reason, I'm pretty inexperienced with this haha.
mihaimoldovan
mihaimoldovan
If you can use resources, just load it like this:

Drawable drawable = getResources().getDrawable(R.drawable.whateveryourimageiscalled);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.