2012-02-20 2 views
1

sqlite 데이터베이스의 이미지를 gridview 또는 갤러리보기에 표시해야합니다. 채울 수있는 방법이 blob로 sqlite에 저장된 이미지가있는 Android 갤러리보기

mMain = (ImageView) findViewById(R.id.ivMain); 
byte[] blob = imgs.getBytes(); //there is a method that will return the bytes from the database 
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob); 
Bitmap bitmap = BitmapFactory.decodeStream(inputStream); 
mMain.setImageBitmap(bitmap); 
내가 그리드 뷰의 안드로이드 자습서를 가지고 있지만이 파일

// references to our images 
private Integer[] mThumbIds = { 
R.drawable.sample_2, R.drawable.sample_3 
... } 

에서 이미지를 가져옵니다
이 하나의보기에 표시하기위한 코드입니다 sqlite 데이터베이스에서 gridview?

UPDATE :
인스턴트 메신저 ImageAdapter는 안드로이드 튜토리얼에서 제공하는 사용 :

이 코드의 주요 활동에
ArrayList<byte[]> image_arr = new ArrayList<byte[]>(); 
//loop through all images on sqlite 
for(int l = 0 ;l< db.getAllImages().size(); l++){ 
    Image imgs = db.getAllImages().get(l); 
    byte[] blob = imgs.getBytes(); 
    image_arr.add(blob); 

    ByteArrayInputStream inputStream = new ByteArrayInputStream(blob); 
    Bitmap bitmap = BitmapFactory.decodeStream(inputStream); 
    // mMain.setImageBitmap(bitmap); 
} 
//TODO; find way to make the bitmap get to the ImageView 

Gallery gallery = (Gallery) findViewById(R.id.gallery); 
gallery.setAdapter(new ImageAdapter(this)); 

그래서 내가 전달하는 방법을 찾아야 :
http://developer.android.com/resources/tutorials/views/hello-gridview.html
내 코드이된다 다른 파일에있는 ImageView의 리소스.

답변

0
private void getDataAndPopulate() { 

    image = new ArrayList<byte[]>(); 
    caption = new ArrayList<String>(); 

    cursor=db.rawQuery("select * from NAME",null); 


    while (cursor.moveToNext()) { 

     byte[] temp_image = cursor.getBlob(2); 
     String temp_caption = cursor.getString(1); 
     String temp_id= cursor.getString(0); 
     image.add(temp_image); 
     caption.add(temp_caption); 
     id.add(temp_id); 
    } 
    String[] captionArray = (String[]) caption.toArray(
      new String[caption.size()]); 

    ItemsAdapter itemsAdapter = new ItemsAdapter(Item_show_grid.this, R.layout.item_grid,captionArray); 
    gv.setAdapter(itemsAdapter); 

} 
+0

와우! 당장 내가 확인해 볼게. 의견을 주셔서 감사합니다 –

+0

감사합니다 @ aashutosh, ArrayList image = new ArrayList (); 아이디어 바이트 배열을 처리하는 데 도움이, ItemsAdapter, 전달할 것입니다 있지만이 ItemsAdapter 현재 내가 샘플 어댑터를 사용하여 더 설명 해주십시오 : http://developer.android.com/resources/tutorials/views/hello-gridview .html –

관련 문제