나는 사진을 SQLite에 blob로 저장하려고한다. mCurrentMediaPath는 사진이 저장 될 현재 경로입니다. 이제 사진을 찍은 후 버튼을 눌러 저장해야합니다 (의도 한 것 같아요).안드로이드 데이터베이스에 blob로 사진을 저장하는 방법
public Uri insert(byte[] image) {
return getContentResolver().insert(MyContentProvider.CONTENT_URI7, createContentValues(image));
}
private ContentValues createContentValues(byte[] image) {
ContentValues docsInsert = new ContentValues();
docsInsert.put(Db.COLUMN_FILETYPE, "PHOTO");
docsInsert.put(Db.COLUMN_NAME, mCurrentMediaPath);
docsInsert.put(Db.COLUMN_FILE, image);
return docsInsert;
}
// convert from bitmap to byte array
public byte[] getBytesFromBitmap(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 70, stream);
return stream.toByteArray();
}
private void dispatchMediaIntent(int actionCode) {
switch(actionCode) {
case ACTION_TAKE_PHOTO:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = null;
try {
f = setUpPhotoFile(ACTION_TAKE_PHOTO);
mCurrentMediaPath = f.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
} catch (IOException e) {
e.printStackTrace();
f = null;
mCurrentMediaPath = null;
}
startActivityForResult(takePictureIntent, actionCode);
break;
case ACTION_TAKE_VIDEO:
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoIntent, actionCode);
break;
default:
break;
}
}
어디에서 삽입해야합니까? DBA는 데이터베이스 클래스의 객체이다
//SAVING TO DATABASE
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentMediaPath, bmOptions);
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentMediaPath, bmOptions);
insert(getBytesFromBitmap(bitmap));
저장하여 데이터베이스에서 이미지의 경로 대신 방울 – Raghunandan
로 이미지를 저장하는 내 게시물의 첫 번째 줄을 읽어주세요. – user2224135
데이터베이스에 이미지를 많이 저장하면 더 많은 공간을 차지합니다. 대신 이미지의 경로를 저장할 수 있습니다. – Raghunandan