Building Bitmap from sdcard image

Posted: June 13, 2011 in Uncategorized

This is the easiest way to load bitmaps from the sdcard. Simply pass the path to the image to BitmapFactory.decodeFile() and let the Android SDK do the rest.

Activity File

package higherpass.TestImages;
 import android.os.Bundle;
 import android.widget.ImageView;
public class TestImages extends Activity {
 /** Called when the activity is first created. */
 public void onCreate(Bundle savedInstanceState) {
 ImageView image = (ImageView) findViewById(;
 Bitmap bMap = BitmapFactory.decodeFile("/sdcard/test2.png");

All this code does is load the image test2.png that we previously copied to the sdcard. The BitmapFactory creates a bitmap object with this image and we use the ImageView.setImageBitmap() method to update the ImageView component.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s