-1

I cannot get Android to load .png images as bitmaps, I'm not sure if it possible to do this and I've been searching for an hour to no avail, regardless here's the code segment I have:

AssetManager assets;
Options options = new Options();
options.inPreferredConfig = Config.ARGB_8888;

InputStream in = assets.open(fileName);
Bitmap bitmap = BitmapFactory.decodeStream(in);

I've successfully used this code with .bmp files but I'm pretty sure you can load other file types other then .bmp as bitmaps. Any help would be appreciated.

An example for filename would be something like "background.png".

user2350603
  • 21
  • 1
  • 2
  • The above code can't work *at all*. It wouldn't even compile, as you never assign `assets`. Maybe your code sample is incomplete, but so is your question: What makes you think that it won't load? Is there an error message, or some other indication? – 323go Jan 22 '14 at 22:24
  • 1
    First of all, a bitmap is not a type of file. It is an in memory representation of an image. A BMP file just happens to be a file containing an uncompressed copy of a bitmap. So, you don't load PNGs as bitmaps. You create a bitmap from a PNG file. That said, "I cannot get Android to load .png images" tells us nothing. What happens when you try? (BTW, it is of course entirely possible to load a PNGs into a bitmap. Many million users use many thousands of apps to do it many times a day. – Simon Jan 22 '14 at 22:24
  • Welcome on SO. I suggest you to have a look to our Tour guide : http://stackoverflow.com/tour that will teach you how to post question and what to do first, like searching on SO for an existing answer. Good Luck. – ForceMagic Jan 22 '14 at 22:41

1 Answers1

4

Inside an activity:

int resourceId = R.drawable.yourpng;
Bitmap bmp = BitmapFactory.decodeResource(getResources(), resourceId);

yourpng.png should be in res/drawable-nodpi