您可以将图像转换为字节数组,并将该字节数组存储在数据库中的blob中。您可以将图像作为字节数组从数据库中检索回来。
如何从imageview获取字节数组:
ImageView iv = (ImageView) findViewById(R.id.splashImageView);Drawable d = iv.getBackground();BitmapDrawable bitDw = ((BitmapDrawable) d);Bitmap bitmap = bitDw.getBitmap();System.out.println(".....d....."+d);System.out.println("...bitDw...."+bitDw);System.out.println("....bitmap...."+bitmap);ByteArrayOutputStream stream = new ByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);byte[] imageInByte = stream.toByteArray();将字节数组存储在数据库中:
ContentValues cv = new ContentValues();cv.put(CHUNK, buffer); //CHUNK blob type field of your tablelong rawId = database.insert(TABLE, null, cv); //TABLE table name
从字节数组中检索图像:
public static Bitmap convertByteArrayToBitmap( byte[] byteArrayToBeCOnvertedIntoBitMap){ bitMapImage = BitmapFactory.depreByteArray( byteArrayToBeCOnvertedIntoBitMap, 0, byteArrayToBeCOnvertedIntoBitMap.length); return bitMapImage;}


