Java decodeByteArray返回null

Java decodeByteArray返回null,java,android,Java,Android,我读取drawable并将其保存到数据库中。我进一步从数据库中读取,但得到null。 你能帮帮我吗 以下是我如何写入数据库: BitmapDrawable drawable = (BitmapDrawable) imageResult.getDrawable(); Bitmap data = drawable.getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); data.compress(Compre

我读取drawable并将其保存到数据库中。我进一步从数据库中读取,但得到null。 你能帮帮我吗

以下是我如何写入数据库:

BitmapDrawable drawable = (BitmapDrawable) imageResult.getDrawable();
Bitmap data = drawable.getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
data.compress(CompressFormat.JPEG, 100, stream);

db = dbHelp.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("data", stream.toByteArray());

db.insert("table", null, cv);
db = dbHelp.getReadableDatabase();
String getProjects = "select data from table where id = (select max(id) from table);";
Cursor cu = db.rawQuery(getProjects, null);
cu.moveToFirst();
data = BitmapFactory.decodeByteArray(cu.getBlob(0), 0, cu.getBlob(0).length); //here is null
以下是我如何从数据库中读取数据:

BitmapDrawable drawable = (BitmapDrawable) imageResult.getDrawable();
Bitmap data = drawable.getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
data.compress(CompressFormat.JPEG, 100, stream);

db = dbHelp.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("data", stream.toByteArray());

db.insert("table", null, cv);
db = dbHelp.getReadableDatabase();
String getProjects = "select data from table where id = (select max(id) from table);";
Cursor cu = db.rawQuery(getProjects, null);
cu.moveToFirst();
data = BitmapFactory.decodeByteArray(cu.getBlob(0), 0, cu.getBlob(0).length); //here is null
编辑:

BitmapDrawable drawable = (BitmapDrawable) imageResult.getDrawable();
Bitmap data = drawable.getBitmap();

ByteArrayOutputStream stream = new ByteArrayOutputStream();
data.compress(CompressFormat.JPEG, 60, stream);

db = dbHelp.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("data", stream.toByteArray());

db.insert("table", null, cv);

谢谢你的回复。我得到的错误窗口已满。请求的第行字节[]的分配imgByte=cur.getBlob(0);我得到的错误窗口已满。请求的第行字节[]的分配imgByte=cur.getBlob(0);请在保存时压缩你的位图,我用60压缩时更新了代码我会丢失位图的质量吗?