By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,796 Members | 1,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,796 IT Pros & Developers. It's quick & easy.

Store Image inside XML

P: n/a
Hi,

I need to store an image from a Graphics object(.NET) inside a xml
data island. Anyone might have came accross or have an idea how to do
this. Please share.

Thanks & Regards,
Raghu, CSS India
+91 98402 56561

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Raghavendra RAV wrote:
I need to store an image from a Graphics object(.NET) inside a xml
data island. Anyone might have came accross or have an idea how to do
this. Please share.


XML doesn't support storing binary data directly, use Base64 encoding
(e.g. use XmlTextWriter.WriteBase64() method).

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2

P: n/a
Hi Oleg,

Thanks for the reply.

It is correct that XML doesnt support binary data. If i manage to
store image inside xml, pls suggest me how can i get the image back on
my web page (possibly using xslt).

Also if possible pls suggest me how to save image in Graphics object
of .NET to base64 data.
Thanks and Regards,
Raghu, CSS India
+91 94440 37040

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

P: n/a
> Also if possible pls suggest me how to save image in Graphics object
of .NET to base64 data.


Have a look at
Convert.ToBase64String
Regards,

Victor
Nov 12 '05 #4

P: n/a
Raghavendra RAV wrote:
It is correct that XML doesnt support binary data. If i manage to
store image inside xml, pls suggest me how can i get the image back on
my web page (possibly using xslt).
XML is text based format. So to store binary data in it you must encode
it. Usually Base64 encoding is used. When you put image to XML - encode
it (e.g. using XmlTextWriter.WriteBase64() method).
When you read XML, you need to decode image (e.g. using
XmlTextReader.ReadBase64() method).
Also if possible pls suggest me how to save image in Graphics object
of .NET to base64 data.


Basically XML API can handle it itself, but if you want take over - use
Convert.ToBase64String()/Convert.FromBase64String() methods.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #5

P: n/a
> It is correct that XML doesnt support binary data. If i manage to
store image inside xml, pls suggest me how can i get the image back on
my web page (possibly using xslt).


.... I think that there is no "direct" way to embedd the image into a web
page after you've decoded it from Base64.

What happens when a browser reads an html file is that it makes an
additional request for every image it finds defined inside the html code -
they're two different files on the web server, and two different http calls
from the browser.

So, I think it's gonna be *difficult* to use xslt or any other medioum and
"embed" the image inside the html.
( of course I'm not an HTTP expert, but I've been working on web sites for
years and have never come across html that contains the full image data
instead of a link to the actual source of the image :? ... )

Of course, nothing prevents you from actually saving the image on the file
system, and just modifying your html link src to point to the right file on
the web server - although that would be A LOT of reading/writing to the disk
and I'd try to avoid it at all costs ...

Angel
O:]
Nov 12 '05 #6

P: n/a
Actually you can display base-64 images inline, using the data url format -
see the spec. at http://www.ietf.org/rfc/rfc2397.txt .

You'd have to use xslt to convert the xml to something in the format
<IMG SRC="data:image/gif,base64;[...]">where the [...] contains your base-64
string.The only issue with this is the size limit on HTML tags, which is
usually 1,024 bytes. This inline data url method is only meant for very
small amounts of data.Hugo Rodger-Brownhttp://hugo.rodger-brown.com
Nov 12 '05 #7

P: n/a
Hi Brown,

Exactly this kind of this is what i was expecting. Thank you so much
for ur reply. I am yet to test this and if i get any issues i may need
ur help.

Thanks,
Raghu, CSS India
+91 94440 37040

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #8

P: n/a
Well, I stand corrected ! Thanks for the post Hugo, that was something I'd
never seen before, and it's certainly useful in many cases. Do you happen to
know when support for this became commonplace ? I'm afraid that I left html
guis a few years ago and .. god, am i obsolete ?!??!?

Cheers,
Angel
O:]

"Hugo Rodger-Brown" <hu**@coldhams.com> wrote in message
news:eG**************@TK2MSFTNGP11.phx.gbl...
Actually you can display base-64 images inline, using the data url format - see the spec. at http://www.ietf.org/rfc/rfc2397.txt .

You'd have to use xslt to convert the xml to something in the format
<IMG SRC="data:image/gif,base64;[...]">where the [...] contains your base-64 string.The only issue with this is the size limit on HTML tags, which is
usually 1,024 bytes. This inline data url method is only meant for very
small amounts of data.Hugo Rodger-Brownhttp://hugo.rodger-brown.com

Nov 12 '05 #9

P: n/a
Hugo Rodger-Brown wrote:
Actually you can display base-64 images inline, using the data url format -
see the spec. at http://www.ietf.org/rfc/rfc2397.txt .

You'd have to use xslt to convert the xml to something in the format
<IMG SRC="data:image/gif,base64;[...]">where the [...] contains your base-64
string.The only issue with this is the size limit on HTML tags, which is
usually 1,024 bytes. This inline data url method is only meant for very
small amounts of data.Hugo Rodger-Brownhttp://hugo.rodger-brown.com


Of course it should be mentioned IE doesn't support this cool stuff.
Another option to give a shot is MHT format, but I never tried that.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #10

P: n/a
One more option would be to go for VML if your graphic could be represented
as a vector type image and you are using IE, or SVG + a plugin if you need
cross browser support.

Also, is there no way that you could just use a URL inside your XML data,
and keep the graphic as an external binary resource?

Nigel

Nov 12 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.