Solved

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

Posted on 2004-04-22
6
419 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:dishanf
Comment Utility
you must first get the binay data and stored it into as gif.. then you can show it..
0
 
LVL 8

Accepted Solution

by:
dishanf earned 84 total points
Comment Utility
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
Comment Utility
0
 

Assisted Solution

by:imhauser
imhauser earned 83 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now