473,809 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BinaryWrite an Image from a binary string

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.G etBytes(Configu rationSettings. AppSettings["PixelBinaryDat a"].ToString())
httpContext.Res ponse.ContentTy pe = "image/gif";
httpContext.Res ponse.BinaryWri te(bytes)
Nov 15 '05 #1
2 6144
Bammer22 wrote:
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.G etBytes(Configu rationSettings. AppSettings["PixelBinaryDat a"].ToString());
httpContext.Res ponse.ContentTy pe = "image/gif";
httpContext.Res ponse.BinaryWri te(bytes);


I suspect that the string in the web.config is a hex string. Encoding
that to UTF8 will not give you what you want.

You probably want something like (I'm probably duplicating something in
the framework that I've overlooked):

public static byte [] hex2bin( string s) {
if (s == null) {
throw new ArgumentNullExc eption("s");
}
if ((s.Length % 2) != 0) {
throw new FormatException ("parameter 's' must have an even
number of hex characters");
}

byte [] result = new byte[ (s.Length)/2];

for (int i = 0; i < result.Length; i++) {
result[i] = byte.Parse( s.Substring( i*2, 2),
System.Globaliz ation.NumberSty les.AllowHexSpe cifier);
}

return result;
}
--
mikeb
Nov 15 '05 #2
Bammer22 <an*******@disc ussions.microso ft.com> wrote:
Thanks mike,
seems like I have a problem since my string is prefixed with 0x.


So take the substring from position 2 and then pass it into hex2bin...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3894
by: Kevin Humphreys | last post by:
Hi, How can I output the Response.BinaryWrite content in an asp page that has html tags inside? I need to write the binary data to the client browser inside the html tags. Thanks In Advance, Kevin.
1
3798
by: Kevin Humphreys | last post by:
Hi All, Please help me regarding the 'Response.BinaryWrite' I am making one web application where I need to store some of client logo's and others images. In this context I am able to store images into .DB file and even able to display into browser to. But it seems to be 'Response.BinaryWrite' does not support 'html/text' hearder if you user 'BinaryWrite'? I had tried many way to do so but its does not write binary if pages content...
0
2562
by: Bill | last post by:
I'm using the example shown at : http://support.microsoft.com:80/support/kb/articles/q276/4/88.asp It involves using ASP/VbScript and ADODB.Stream to read binary data from a *.DOC or *.RTF file and then send it to the user with Response.ContentType and BinaryWrite. Everything works fine until I try to Replace() certain strings in the *.RTF file with my own data. I'm assuming Replace() is choking on the binary characters, or
5
17895
by: katrinaVictim | last post by:
Question: I get the eror listed at the bottom of the post. What can I do to make the response of the x1.send a "binary" type? Or, in general, how can I just "make this work"? <%@ Language=VBScript %> <% Response.Buffer = TRUE Response.ContentType = "image/jpg"
2
6089
by: Nik | last post by:
I am trying to write out the equivalent of this asp statement in c#: Response.BinaryWrite(chrb(239) & chrb(187) & chrb(191)) 'BOM = EF BB BF string binString = "11111111"; byte myBin = Convert.ToByte(binString); Response.BinaryWrite(myBin); binString = "10111011"; myBin = Convert.ToByte(binString); Response.BinaryWrite(myBin); binString = "10111111";
2
1246
by: Vinay | last post by:
Hi All: I have a frameset (right and left). In the left frame I have a listbox that contains items. When the user clicks on any one of these items (each item points to either a word document or an image) - I'd like to show this (image or word document) in the frame on the right. Would anyone have any ideas on how I can do this? The code I currently have is: I am trying to figure out what response.redirectlocation does - without much...
1
2782
by: Alex Nitulescu | last post by:
Hi. I have a WebService which provides a webmethod which returns a byte array representing a picture. The method's signature is: <WebMethod(Description:="Shows something nice every time !")> Public Function GetRandomImage() As Byte() I then have a test application (with a web reference to my web service) which has the following code: Public Class BinaryWebServiceTest
1
4235
by: mattridings | last post by:
Hi gang, Have a script that works fine. However, it's really cpu intensive and I'm looking for suggestions on a) whether or not that's normal and if so b)a better way of doing it. Script is very simple, there is a folder of files with numeric names. The real file name is stored in the database. User clicks on link that executes script and provides database record id. Record is looked up, file name is found, and browser is delivered...
5
3405
by: andrew.douglas11 | last post by:
Hello, I'm looking to display an image in the browser using a binary string containing all the bytes that make up a GIF image. I've tried all the standard encodings in System.Text.Encoding, but the images aren't showing up. I'm using the approach where I'm setting ImageURL = "GetImage.aspx?id=1". Here's my code from GetImage.aspx: Dim imageData As String = the binary data representing a .gif file Dim imageBytes() As Byte =
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.