Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a blob image in Android?

I want to display an image which is saved into database in blob form on my Android. I am using ImageView as image container. Please suggest me something soon.

Regards, Rahul

like image 975
Rahul Avatar asked Jan 04 '11 07:01

Rahul


People also ask

What is blob in Android?

An SQL BLOB is a built-in type that stores a Binary Large Object as a column value in a row of a database table. By default drivers implement Blob using an SQL locator(BLOB) , which means that a Blob object contains a logical pointer to the SQL BLOB data rather than the data itself.

What is blob format image?

A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.


1 Answers

Basically there are two options:

  1. Buffer read from BLOB wrap in InputStream so you will have InputStream which will point to BLOB data
  2. Save BLOB data to temporary file open it as FileInputStream - so in the end you'll again have stream over image data

in both cases you can easily convert InputStream to bitmat data in a way:

InputStream is; //stream pointing to your blob or file
//...
imageView=new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(BitmapFactory.decodeStream(is));
like image 143
Barmaley Avatar answered Sep 20 '22 08:09

Barmaley