我已将blob数据插入到sqlite中并从sqlite中检索到时间blob数据未在imageview上设置为位图。让msg无法加载。所以请帮我解决我的代码问题。以下是我的代码。
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
imageView.setImageBitmap(bitmap);
ByteArrayOutputStream stream= new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte imginbyte[]=stream.toByteArray();
byte temp[]=imginbyte;
myDb.execSQL("INSERT INTO tableimage VALUES('"+temp+"');");
Cursor c= myDb.rawQuery("SELECT * FROM tableimage", null);
c.moveToLast();
byte asd[]= c.getBlob(c.getColumnIndex("imgpath"));
byte img[]=null;
// BitmapFactory.decodeByteArray(asd, 0, asd.length);
ImageView iv=(ImageView)findViewById(R.id.img2);
ImageView iv1=(ImageView)findViewById(R.id.img3);
iv.setImageBitmap( BitmapFactory.decodeByteArray(asd, 0, asd.length));
iv1.setImageBitmap( BitmapFactory.decodeByteArray(asd, 0, asd.length));
答案 0 :(得分:1)
试试这个
ByteArrayInputStream imageStreamFront = new ByteArrayInputStream(asd);
Bitmap bitFrontImage = BitmapFactory.decodeStream(imageStreamFront);
if(bitFrontImage!=null)
{
iv.setImageBitmap(bitFrontImage, 40);
}
答案 1 :(得分:1)
没有blob存储图像和retrive。与字符串数据库见下面的代码
YourGroup:LibraryProject:1.0-SNAPSHOT