blob 数据未在 imageview 上设置为位图 android
blob data not set as bitmap on imageview android
我已将 blob 数据插入到 sqlite 中,并从 sqlite 中检索到 blob 数据未在 imageview 上设置为位图。给味精加载失败。所以请帮助我的代码。以下是我的代码。
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));
试试这个
ByteArrayInputStream imageStreamFront = new ByteArrayInputStream(asd);
Bitmap bitFrontImage = BitmapFactory.decodeStream(imageStreamFront);
if(bitFrontImage!=null)
{
iv.setImageBitmap(bitFrontImage, 40);
}
没有 blob 存储图像和检索。使用字符串数据库见下面的代码
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
imageView.setImageBitmap(bitmap);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImageString = Base64.encodeToString(b, Base64.DEFAULT);
byte[] bytarray = Base64.decode(encodedImageString, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,
bytarray.length);
myDb.execSQL("INSERT INTO imgtbl VALUES('"+encodedImageString+"');");
Cursor c= myDb.rawQuery("SELECT * FROM imgtbl", null);
c.moveToFirst();
String img=c.getString(0);
byte[] byarray = Base64.decode(img, Base64.DEFAULT);
Bitmap bmimg = BitmapFactory.decodeByteArray(byarray, 0,
byarray.length);
ImageView iv=(ImageView)findViewById(R.id.img2);
ImageView iv1=(ImageView)findViewById(R.id.img3);
iv.setImageBitmap(bmimg);
iv1.setImageBitmap(bmimg);
我已将 blob 数据插入到 sqlite 中,并从 sqlite 中检索到 blob 数据未在 imageview 上设置为位图。给味精加载失败。所以请帮助我的代码。以下是我的代码。
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));
试试这个
ByteArrayInputStream imageStreamFront = new ByteArrayInputStream(asd);
Bitmap bitFrontImage = BitmapFactory.decodeStream(imageStreamFront);
if(bitFrontImage!=null)
{
iv.setImageBitmap(bitFrontImage, 40);
}
没有 blob 存储图像和检索。使用字符串数据库见下面的代码
bitmap = android.provider.MediaStore.Images.Media
.getBitmap(cr, selectedImage);
imageView.setImageBitmap(bitmap);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String encodedImageString = Base64.encodeToString(b, Base64.DEFAULT);
byte[] bytarray = Base64.decode(encodedImageString, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,
bytarray.length);
myDb.execSQL("INSERT INTO imgtbl VALUES('"+encodedImageString+"');");
Cursor c= myDb.rawQuery("SELECT * FROM imgtbl", null);
c.moveToFirst();
String img=c.getString(0);
byte[] byarray = Base64.decode(img, Base64.DEFAULT);
Bitmap bmimg = BitmapFactory.decodeByteArray(byarray, 0,
byarray.length);
ImageView iv=(ImageView)findViewById(R.id.img2);
ImageView iv1=(ImageView)findViewById(R.id.img3);
iv.setImageBitmap(bmimg);
iv1.setImageBitmap(bmimg);