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();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm= BitmapFactory.decodeStream(bis);
bis.close();
is.close();

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(),
R.drawable.myimage);

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

What am I missing?

Thanks,
Simon.

--