1

您好,我将图像作为 blob 存储在数据库中,并以字符串形式从数据库中检索图像。现在我想在 imageview 中设置这个图像。我试图将它转换为位图但没有显示它。我已经完成了这样的代码。请帮助提前感谢

在日志中,我正在播种这种格式的照片:[ B@4052b078 ]

byte[] imageAsBytes = Base64.decode(sp_photo.getBytes(), 0);
alert_photo.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, Bytes.length));

这里 sp_photo 是我的照片字符串路径。并且 alert_photo 是图像视图。请告诉我

4

2 回答 2

2

试试这个,它可能会工作:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inPurgeable = true;
options.inInputShareable = true;
options.inTempStorage = new byte[1024 *32];

Bitmap bm = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length, options);
alert_photo.setImageBitmap(bm);
于 2012-11-10T12:13:10.583 回答
0

试试这个示例代码......

http://code.google.com/p/android-newbie-sourcecode/source/browse/trunk/ImageToDatabase/?r=6

于 2012-11-10T12:38:32.890 回答