Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-22
6
Medium Priority
?
451 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 336 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 332 total points
ID: 10896836
0
 

Assisted Solution

by:imhauser
imhauser earned 332 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

597 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