Click here to Skip to main content
Email Password   helpLost your password?

Sample Image - screen_shot_Genx.jpg

Introduction

Looking at the .resx file that VS.NET uses to store resources such as images, I thought wouldn't it be cool to have a XML file where you can store images and other info for you app and at startup your app gets the look and feel from the XML file dynamically. You can then change the look and feel by changing the XML file, maybe over the internet! A little investigation showed that .NET namespace System.XML has 2 great classes XMLTextWriter and XMLTextReader which does all the hard work for you with their Read/WriteBase64 methods.

m_XMLWriter.WriteStartElement("",NodeName,"");

<code>m_XMLWriter.WriteBase64(ImageBinaryBuffer,0,ImageBinaryBuffer.Length);

m_XMLWriter.WriteEndElement();

So here is my quick and dirty app, which uses 2 classes CLookXMLReader and CLookXMLWriter to do the putting in the binary and getting the binary out to bitmap or an icon. You basically use the Writer to put the images into the XML, then the reader can be used at a separate app to get the images out from the XML. Made the code a bit messy when reading the binary out from the XML, there must be a better way to it, please let me know! I hope you dont judge coding skills by just looking at this app only (I am usually much better!) :)

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionHow to convert .ai file(Adobe Illustrator File) to .bmp(BitMap) file in c#
Santhosh_B_K
2:08 16 Apr '07  
How to convert .ai file(Adobe Illustrator File) to .bmp(BitMap) file in c#
Questionhow do I pass an image from nodes in the xml to a component on a form
Try74
2:15 8 Jan '07  
I am trying to pars an XML file where there is an image associated with the componenet. (I think that I need to be able to open the image save it as a string)
my XML reads somthing like this

<button ID = "1">
.
.
.
<image>
      <imageid>1</imageid>
      <imagename>back</imagename> THIS is the bit that i can not pars at the momenet
      <horozontalalignment>0</horozontalalignment>
</image>
.
.
</button>

Can any one help please, I am having a mental block Smile

Generalssl code
saroj yadav
2:20 16 Oct '06  
please send ssl code
GeneralThank You
dboucher
18:01 21 Jul '05  
This code was remarkably helpful. Works great -- many thanks!

Big Grin
GeneralBinary to XML to Binary to XML fails
nordhaus
12:34 18 May '05  
So i have an app that manipulates images.

I can load an image and save it as XML, ok.
I can then load the XML and extract the image, ok
But then when I try to save it as XML again and get the error:

"An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occured in system.drawing.dll

Additional information: A generic error occurred in GDI+."

Any ideas?
The image is a jpg, and is stored in a memory stream.
GeneralXmlTextReader and binary data
Anonymous
5:45 10 Dec '02  
Hi,
I have and XML document, dtd and xsl file stored as blobs
within an Oracle database. I am using the following code
within my web service to retrieve the blobs from the
database, however I have no idea how to then load them
into the XMLTextReader. Presumably the data returned in
the dataset will need to be converted from binary into
something the XMLTextReader will understand. I'm pretty
new to .Net and would appreciate any help as I'm tearing
my hair out over this one!!

My existing code:

string sSQL = "SELECT THE_FILE, THE_DTD, THE_XSL from
WSTest";
OracleDataAdapter oDA = new OracleDataAdapter
(sSQL,myConnection);
OracleCommandBuilder oCB = new OracleCommandBuilder(oDA);
DataSet oDs = new DataSet("WSTest");
oDA.MissingSchemaAction = MissingSchemaAction.AddWithKey;
oDA.Fill(oDs,"WSTest");
DataRow oDR;
oDR = oDs.Tables["WSTest"].NewRow();
oDR = oDs.Tables["WSTest"].Rows[0];


Thanks,
Sharon

Generaldbconsts.obj
Reza_Y
23:07 20 Sep '02  
Hi.
I want install a component in C++ Builder 6 but this
component needs a file: dbconsts.obj, whitout it
execute in C++ Builder 5.
Please help me.
Thanks.
GeneralSending the image size
Vinla
1:24 20 Sep '02  
I noticed in the code to this article that the author was looking for a better way to create the right size of byte array in which to store the image data when reading in the image from the xml. I dealt with this by including a size attribute in the xml element containing the image data

i.e. <imagedata size="284375">[image data]</imagedata>

You can then read this value just before extracting the data

int size = Int32.Parse(xml.GetAttribute("size"));
byte[] imageData = new byte[size];
xml.ReadBase64(imageData,0,imageData.Length);


GeneralBitmap to a bytearray
jeetu
5:44 26 Aug '02  
If I already have the image loaded in memory, is there any way for me to get it shoved into a byte array? The obvious long way would be to save to disk and re-load it, but I'm sure there is a better way.....
GeneralRe: Bitmap to a bytearray
Kamen Nikolov
7:45 26 Sep '03  
Yes,

just use

byte[] theByteArray = Convert.FromBase64String(string theString);

It works for me...

Smile

Kamen Nikolov

kamen.nik@sympatico.ca


GeneralRe: Bitmap to a bytearray
Kamen Nikolov
7:55 26 Sep '03  
If you have the image as an image object and not as an XML node, then use this:

MemoryStream memStream = new MemoryStream();
bitmapObject.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);
int ImageSize = Convert.ToInt32(memStream.Length);
byte[] ImageBytes = new byte[ImageSize];
memStream.Position=0;
memStream.Read(ImageBytes, 0, ImageSize);
memStream.Close();
return ImageBytes;


GeneralXml bunary vb6 problem in c#
bcapuano
13:25 30 Jul '02  
In vb6 with msxml3 i do the following code :

Set oElement = xmlDOMDocument.createElement("SIGNATURE")
oRoot.appendChild oElement
oElement.dataType = "bin.base64"
oElement.nodeTypedValue = rsResult.Fields("Signature").Value

to assign binary data from one recordset to a MSXml Node

I try to do the same in C# using System.Xml, but i want a source code that don't use temprary files. I tried with the XmlTextWriter and XmlTextReader but I cant' make them work ...
any ideas

Bruno Capuano Software Engineer
PECTRA Technology Inc.
All the Solutions in One Product
+54(351)4245756 - int. 301
Pectra.Com
GeneralRe: Xml bunary vb6 problem in c#
Anonymous
12:44 4 Oct '02  
Use a System.IO.MemoryStream. Its basicly a wraper for a byte array in memory.
GeneralXml Quik Buider
shak
20:48 30 Jun '02  
Hey people check it out XML Quik builder beta version from www.editml.com
Its converts XSD to GUI in seconds and can be saved as XML
make use of this tool, and save ur time

go to www.editml.com

GeneralRe: Xml Quik Buider
Christian Graus
21:09 30 Jun '02  
We don't take kindly to spammers in these here parts.

If you want an ad on CP, contact Chris for pricing details.


Christian

I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
Remember that amateurs built the ark. Professionals built the Titanic.
GeneralCan you encode the binary information to a string
Anonymous
11:56 13 Jul '01  
I would like to encode the binary information in an xml document but i would prefer not to create a file. I would like to writer the xml to a string instead of a file. Any Ideas..





GeneralRe: Can you encode the binary information to a string
Todd Smith
12:36 13 Jul '01  
UUENCODE or MIME encode it just like emails do.
GeneralRe: Can you encode the binary information to a string
Anonymous
9:51 16 Jul '01  
Sounds goods.. But how do i do that with C#.. Will this allow me to take binary informaion an write to a string as base64.

GeneralRe: Can you encode the binary information to a string
Nathan Blomquist
7:07 12 Jun '02  
You could just do:

System.Convert.ToBase64String(myByteArray);

This should work in any .NET language.

Hope that helps....


---------------------------
Hmmm... what's a signature?
GeneralAnything like this in C++
Darren Schroeder
11:39 16 Jun '01  
Do you know of any code like this in C or C++ internal to windows? By that I mean without 3rd party utils.
GeneralRe: Anything like this in C++
wahid
6:02 18 Jun '01  
Hi,

The following bit of code can read the decoded binary data out from the xml node(m_pCurrentNode), so write would be similar(I suppose)..
// set the data type to base64 for the node so that automatic decoding
// can take place.
CString strDataType = "bin.base64";
BSTR bstrDataType =strDataType.AllocSysString();
m_pCurrentNode->put_dataType(bstrDataType);
SysFreeString(bstrDataType);

VARIANT vtype;
vtype.vt = VT_ARRAY;

m_pCurrentNode->get_nodeTypedValue(&vtype);


Last Updated 14 Jun 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010