-1

我有一个最初设置为可绘制资源的 ImageButton。在活动期间,我想将图像设置为用户照片的位图。拍照和保存工作正常,但 ImageButton 的图像没有改变。

这是我的代码:

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);
4

1 回答 1

0

要做到这一点,你可以尝试使用 sd 卡。

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

在活动的onCreate方法中,将您的按钮分配给一个变量,然后设置一个资源或位图,该资源或位图将使用BitmapFactory类从文件中解码。
您可以使用文件资源管理器从 sd 卡中选择图像并将该图像路径分配给BitmapFactory.decodeFile().

于 2013-07-05T15:51:43.423 回答