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. What is the purpose of /system/lib/hw/sensors.default.so ?

I am looking to fill in the sensor_default for the HAL layer. I have
several different kernel drivers for different sensor devices
(accelerometer, magnetometer, proximity, etc) and I am trying to get
them all to register. When I have done the build and try to invoke the
sensor manager, I get the following messages in the logcat:

E/HAL     (  298): load: module=/system/lib/hw/sensors.default.so
error=Cannot find library
D/SensorManager(  298): found sensor: null, handle=0

I am trying to figure out where the /system/lib/hw/sensors.default.so
comes from and how to include it into my build. Any suggestions would
be appreciated.

unsubscribe: android-porting+unsubscr...@googlegroups.com

2. Has anyone succeeded in displaying non latin-1 characters in Webview after RC33?

String xml = "<html>" +
  "<body>" +
        "Norwegian chars: &aring;&oslash;" +
  "</body>" +
myWebView.loadData(xml, "text/html", "UTF-8");

This code works for latin-1 but as far as I know there are not HTML
entities defined for Latin-2 so I was wondering if there are other
solutions to displaying non latin-1 in a Webview? I've tried encoding
the string given to loadData as UTF-8 but with little success...


3. MapViews with EditText and Overlays?

4. How to get the device model in android?

5. Database installation - Android

6. Problems w/ Custom List Selector

7. Tabbing Between EditText Fields