Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2004, 01:28 PM
Registered User
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default BinaryWrite an image

I am trying to BinaryWrite an image from a binary string that I am storing in the web.config file. The image is just a 1x1 pixel gif. I am setting the content type to "image/gif", but the output is just my string. Any suggestions? Code is below:

byte[] bytes = Encoding.UTF8.GetBytes(ConfigurationSettings.AppSe ttings["PixelBinaryData"].ToString());
httpContext.Response.ContentType = "image/gif";
httpContext.Response.BinaryWrite(bytes);



 
Old March 2nd, 2004, 04:58 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You might want to look into embedded resources for this. I have had good luck with using those for this very purpose. There is a utility you can download that will create a resource file for the image you tell it to convert, then you can just copy the one XML node for that image into an existing resource file. The image resource will get compiled right into the assemble/executable.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 3rd, 2004, 02:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

its a sample to save image file in a Database,I hope u need this.
Code:
                if( FileOpenDlg.ShowDialog() == DialogResult.OK)
                {
                    string file = FileOpenDlg.FileName;
                    System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    byte[] buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, (int)stream.Length);
                    stream.Close();
                    string strName = System.IO.Path.GetFileNameWithoutExtension(file);

                    //SavePic
                    DataRow PicRow;
                    PicRow = dsDabir1.Tables["Images"].NewRow();
                    PicRow.SetParentRow(IncomeRow);
                    PicRow["IsScaned"] = 0;
                    PicRow["ImgPic"] = buffer;
                    dsDabir1.Tables["Images"].Rows.Add(PicRow);
                    buffer = null;
                }//if


Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Upload image-create & save thumbnail-display image angshujit ASP.NET 2.0 Professional 6 July 11th, 2013 10:34 PM
Copy kodak image edit control's image to clipboard vishwanathduddilla Visual Studio 2005 0 November 3rd, 2008 10:10 AM
set image on <asp:Image> stored in DataBase myself.panku ASP.NET 2.0 Professional 1 August 11th, 2008 10:41 AM
Response.BinaryWrite issue alliancejhall ASP.NET 2.0 Basics 1 November 14th, 2007 11:29 PM
Response.BinaryWrite hcweb Classic ASP Basics 0 June 20th, 2007 01:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.