Solved

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

Posted on 2004-04-22
6
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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