2011-03-24 139 views
0

當我試圖將bytearray轉換爲位圖時,我得到了空值。我不知道爲什麼。請給我有用的建議。從數據庫中檢索圖像

super.onCreate(savedInstanceState); 
    setContentView(R.layout.newscreen); 
    TextView name = (TextView)findViewById(R.id.textView1); 
    TextView age = (TextView)findViewById(R.id.textView2); 
    ImageView img = (ImageView)findViewById(R.id.imageView1); 

    db = openOrCreateDatabase(
      "StudentData.db" 
      , SQLiteDatabase.CREATE_IF_NECESSARY 
      , null 
     ); 

    db.setVersion(1); 
    db.setLocale(Locale.getDefault()); 
    db.setLockingEnabled(true); 

    Cursor cur = db.query("stuData", 
       null, null, null, null, null, null); 
      //cur.moveToFirst(); 
    cur.moveToFirst(); 
     //name.setText(cur.getString(1)); 
     //age.setText(cur.getString(2)); 

     // if(bb!=null) 
     //{ 


     //ByteArrayInputStream imageStream = new ByteArrayInputStream(bb); 
      //bs = new BufferedInputStream(bb) 

     //img.setImageBitmap(theImage); 
    while (cur.isAfterLast() == false) { 
      BitmapFactory.Options options = new BitmapFactory.Options(); 
      options.inSampleSize=5; 
      name.append("n" + cur.getString(1)); 
      byte[] bb = cur.getBlob(3); 


      System.out.print("DAta"+bb); 

      for(int i =0;i<bb.length;i++) 
      { 
       System.out.println(bb[i]); 
      } 
      Bitmap theImage = BitmapFactory.decodeByteArray(cur.getBlob(3),0,cur.getBlob(3).length); 

      img.setImageBitmap(theImage); 

      cur.moveToNext(); 
     } 
    cur.close(); 
+1

完全同意@Vladimir,如果您在這裏提出的21個問題中沒有收到任何單一的好答案,我想知道爲什麼您一直問他們這樣做? – Adinia 2011-03-24 09:43:51

回答

0

有幾點要檢查。

  1. 您是否將正確的圖像字節數組插入到數據庫?檢查數組的長度
  2. 從數據庫進行回讀時,檢查數組的長度。
  3. 同時檢查天氣陣列是否爲空。
+0

我已經檢查過所有這些東西,沒有任何誤解。 – 2011-03-25 05:57:38