views:

338

answers:

3

Hello,

I am currently developing a web application that receives data from an on-site database. The database developers have developed some web-services that I am able to call and send/receive data to and from the the database.

When I want to display an image the method returns the image in BLOB format. My question is: what is the best way to convert BLOB to .jpg or .bmp so I can display the image correctly? If someone could point me in the right direction that would be great!

Cheers, Tristan

A: 

There is no one image format associated with BLOB. It's simply a way of putting raw binary in a database. You need to figure out which format it actually is (libmagic may help), then you can convert if needed.

Matthew Flaschen
A: 

byte[] array and mimetype are the key words :)

Chino
+2  A: 

You can create a generic handler (ashx file) and have it return the byte array.

For example, the url http://www.example.com/GetImage.ashx?imageId=1 could contain code to write the bytes received from the image with id of 1.

You will need to implement the handler code yourself to do the database query, etc. and write the bytes out to the response. You will also need to set the response mime type to jpg, png or whatever format your images are in.

Check out this stackoverflow post for more details: http://stackoverflow.com/questions/46788/how-to-bind-a-memorystream-to-aspimage-control

John JJ Curtis