2013-06-05 3 views
1

데이터베이스에 이미지를 저장해야하는 응용 프로그램을 작성 중입니다. 나는 이미지를 바이트로 변환했지만 이미지를 데이터베이스에 저장할 수있는 다른 방법은 없다.데이터베이스에 이미지를 저장하는 방법은 무엇입니까?

+2

내가 일반적으로 이미지를 저장하는 것을 권 해드립니다 정의하고 바로 데이터베이스의 파일 이름과 위치를 referecing. –

+1

나는 안드로이드가 어떻게 작동하는지 모르지만 DB에 이미지 이름을 저장할 수없고 이미지를 디렉토리에 저장할 수 있습니까? – user1032531

답변

4

이미지 경로를 데이터베이스에 저장하고 이미지를 sdcard에 저장하고 데이터베이스의 이미지 경로에서 이미지를 검색 할 수있다.

당신은 문자열 형식의 데이터베이스에서 이미지 경로를 저장할 수
0

..

1

가져 오기 이미지 형태의 SD 카드

if (requestCode == SD_REQUEST) { 
Uri selectedImage = data.getData(); 
String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

Cursor cursor = getContentResolver().query(selectedImage, 
       filePathColumn, null, null, null); 
cursor.moveToFirst(); 

int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
String filePath = cursor.getString(columnIndex); 
cursor.close(); 

Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath); 

testimage.setImageBitmap(yourSelectedImage); 
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byteArray = stream.toByteArray(); 
} 

이미지 저장

3,272,지금 DatabaseAdapter.java

public static final String U_PIC = "picture"; 

그런 다음

private long createUserTableContentValues(long id,byte[] byteImage) { 
     ContentValues values = new ContentValues(); 
     values.put(ID, id); 
     values.put(U_PIC, byteImage); 
return database.insert(IMAGE_INSERT, null, values); 
} 
관련 문제