我想打开相机onclick。它工作正常。现在拍照后我不想在画廊中保存那张照片。我想在sql数据库中保存该图片
答案 0 :(得分: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();
}
}