Solved

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

Posted on 2004-04-22
6
436 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 134
Upgrade code from VS 2010 to VS 2015 7 45
EF5: Update Model from Database not working 3 83
.NET universe documentation poster 2 22
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…
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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