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