我试图将一个图像从字节[]转换为位图,以在Android应用程序中显示图像。Android:如何将字节数组转换为位图?
byte []的值由数据库获得,我检查它不是null。 之后,我想转换图像,但不能成功。该程序显示位图的值为空。
我觉得在转换过程中有一些问题。
如果您知道任何提示,请告诉我。
byte[] image = null;
Bitmap bitmap = null;
try {
if (rset4 != null) {
while (rset4.next()) {
image = rset4.getBytes("img");
BitmapFactory.Options options = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeByteArray(image, 0, image.length, options);
}
}
if (bitmap != null) {
ImageView researcher_img = (ImageView) findViewById(R.id.researcher_img);
researcher_img.setImageBitmap(bitmap);
System.out.println("bitmap is not null");
} else {
System.out.println("bitmap is null");
}
} catch (SQLException e) {
}
谢谢您的回复!请让我知道如何在该方法中提供整个字节数组。 – Benben 2012-07-23 14:17:47
你能指定rset4'变量是什么吗?看到你的发布代码,这似乎有你的图像的字节数组。 – Angelo 2012-07-23 14:20:09
OK,rset4是ResultSet的值,用于存储执行SQL的结果。 'ResultSet rset4 = null; rset4 = stmt4.executeQuery(“select * from images where id =”+ id);' – Benben 2012-07-23 14:26:23