这是我在数据库中插入图像的代码。单击browsebutton2时,如何从数据库中检索相同的图像?
BrowseButton=(Button)findViewById(R.id.BrowseButton);
BrowseButton2=(Button)findViewById(R.id.BrowseButton2);
adapter = new ContactImageAdapter(this, R.layout.screen_list, imageArry);
BrowseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap image = BitmapFactory.decodeResource(getResources(),R.drawable.facebook);
image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
Log.d("Insert: ", "Inserting ..");
db.addContact(new Contact("FaceBook", imageInByte));
}
});
BrowseButton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
答案 0 :(得分:0)
您可以在获取光标后使用以下代码从DB获取图像。
Bitmap fetchedBitmap = null;
public static byte[] b = null;
if(cr.getBLob!=null){
b = cr.getBlob(ColumnIndex); // Column index from which the image have to be fetched
ByteArrayInputStream bais = new ByteArrayInputStream(b);
fetchedBitmap = BitmapFactory.decodeStream(bais);
}