0

这是我在数据库中插入图像的代码。单击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) {
    }
});
4

1 回答 1

0

获取光标后,您可以使用以下代码从数据库中获取图像。

 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);

}
于 2013-02-15T11:21:27.957 回答