0

我想打开相机 onclick。它工作正常。现在拍照后我不想把那张照片保存在画廊里。我想将该图片保存在sql数据库中

4

1 回答 1

0

要在数据库中插入图像,请编写以下代码:

public class CameraHandler implements PictureCallback {
.....
 @Override
 public void onPictureTaken(byte[] data, Camera camera) {
       insertImageInDB(data);
}

public void insertImageInDB(byte[] theImageBytes){
    SQLiteDatabase db               =   dbHelper.getWritableDatabase();

    String sql                      =   "INSERT INTO MY_IMAGES (image_id,other_data,the_image) VALUES(?,?,?)";
    SQLiteStatement insertStmt      =   db.compileStatement(sql);
    insertStmt.bindString(1, id);
    insertStmt.bindString(2,otherData);
    insertStmt.bindBlob(3, theImageBytes);
    insertStmt.executeInsert();
    db.close();
}

}
于 2013-01-05T22:56:17.010 回答