Loading and displaying an image from a resource

by sj » Fri, 30 Apr 2010 13:43:20 GMT

Sponsored Links
 Currently I'm successfully loading and displaying an image from a
webserver using the code below.

URL imgURL = new URL(" http://www.xxx.com/myimage.png" ;);
URLConnection conn = aURL.openConnection();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm= BitmapFactory.decodeStream(bis);

canvas.drawBitmap(bm, 0, 0, null);

What I want to do is load it from a resource.  I've put myimage.png
into res/drawable and referenced the bitmap as follows :-

Bitmap bm = BitmapFactory.decodeResource(getResources(),

However when I try to display it with canvas.drawBitmap(bm, 0, 0,
null); I get a Force Close.

What am I missing?



Other Threads

1. screen Oroentation

Hi guys..

In my application i want to do Screen Orientation

public void onConfigurationChanged(Configuration newConfig)

This is the function that im using in onCreate() method.

But when i use this it is showing an error like

        - Syntax error on token ")", ; expected
        - Syntax error on token "(", ; expected
        - void is an invalid type for the variable onConfigurationChanged

Its an important task..could anyone please respond to resolve my issue

Any help appreciated


2. (TabActivity) How to switch tab from within a "sub" activity

Simple: get rid of the other activities. I really wish developers would
stop doing that -- all you do is make your life more difficult. Just
make the tabs be views in the TabActivity.

Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 1.9 Available!


3. (TabActivity) How to switch tab from within a "sub" activity

4. trying to show a progressdialog in a lengthy task

5. Touiteur premprem

6. onListItemClick problem

7. Home Screen Customization problem