Solved

Convert binary code into jpeg/gif format for web with ASP.NET

Posted on 2004-04-22
6
432 Views
Last Modified: 2012-06-22
I need to display a photo on a page that is stored on an SQL server as binary code. I am a beginner ASP.NET programmer and haven't been able to figure out how to get this done. Please help.
0
Comment
Question by:Manzana05
  • 2
6 Comments
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 10896104
you must first get the binay data and stored it into as gif.. then you can show it..
0
 
LVL 8

Accepted Solution

by:
Dishan Fernando earned 84 total points
ID: 10896127
Basic stucture is like this..

string sSQL = "SELECT Binary FROM ApplicationSetup";
// Binary      
byte []aData = (byte[])m_oDataProvider.ExecuteScalar( sSQL );

// Create a file
FileStream newFile = new FileStream( sPath , FileMode.Create);

// Write data to the file
newFile.Write(Buffer, 0, Buffer.Length);

// Close file
newFile.Close();
0
 
LVL 23

Assisted Solution

by:rama_krishna580
rama_krishna580 earned 83 total points
ID: 10896836
0
 

Assisted Solution

by:imhauser
imhauser earned 83 total points
ID: 10897502
you have to create a aspx page which is going to render the picture
here is the code (Page_Load) :

byte[] buf=(byte[])ds.Tables[0].Rows[0]["Photo"];
MemoryStream ms=new MemoryStream(buf,0,buf.Length);
Bitmap bmp=new Bitmap(ms);
Response.ContentType=ds.Tables[0].Rows[0]["PhotoType"].ToString();
if(Response.ContentType.ToLower().IndexOf("gif")!=-1)
   bmp.Save(Response.OutputStream,ImageFormat.Gif);
else
   bmp.Save(Response.OutputStream,ImageFormat.Jpeg);

Photo is the binary field
PhotoType identify the type of picture whi is stored

you can display it on a web page like this :

<img src="photo.aspx"/>

Eric

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question