-1

I have an ImageButton that is initially set to a drawable resource. During an Activity, I want to set the image to a bitmap of a user photo. The picture taking and saving work correctly, but the ImageButton's image does not change.

Here is my code:

Bitmap bitmap = BitmapFactory.decodeFile(PATH + "/image.jpg");

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, stream);

Log.d(TAG, bitmap.toString());  //prints out android.graphics.Bitmap@41d772a8
rearEndImageButton.setImageBitmap(bitmap);
onepiece
  • 3,279
  • 8
  • 44
  • 63

1 Answers1

0

To do it form sd card you can try with..

Bitmap bmp = BitmapFactory.decodeFile("path_to_file");
ImageButton rearEndImageButton = (ImageButton)findViewById(R.id.rearEndImageButton);
rearEndImageButton.setImageBitmap(bmp);

In the activity onCreate method assign your button to a variable, and then set a resource or Bitmap which will be decoded from a file using the BitmapFactory class.
You can use File explorer to select an image from sd card and assign that image path to BitmapFactory.decodeFile().

ridoy
  • 6,274
  • 2
  • 29
  • 60
  • The code you listed is the same that I have in my question. I don't want to select from a list, I know the path of the image already. – onepiece Jul 05 '13 at 19:28
  • Then use correct image path,confirm your file exists there.See similar things works for textView and imageView,http://stackoverflow.com/questions/6262935/i-want-to-set-an-image-saved-on-sd-card-in-main-layout-background-through-my-app, http://stackoverflow.com/questions/6725718/android-display-image-from-sd-card – ridoy Jul 05 '13 at 19:39