xml| data
It was interesting to see how XML stored data in the past, especially when I saw an article saying that you could use XML instead of SQL server2000 to store data and interactive data, which is still under study. Finally how to access the image to the XML code to fix:
Reading images
Defining an image source and destination XML file
String imgfilename = @ "d:\ China Mobile advertising. JPG ";
String xmlfilename = @ "D:\img.xml";
XmlTextWriter axmltextwriter = new XmlTextWriter (XMLfileName, System.Text.Encoding.Default);
axmltextwriter.formatting = formatting.indented;
Try
{
Axmltextwriter.writestartdocument ();
Axmltextwriter.writecomment ("Contains a BinHex JPEG image");
Axmltextwriter.writestartelement ("JPEG");
Below is a common code for reading images.
System.IO.FileInfo fi = new System.IO.FileInfo (imgfilename);
int size = (int) fi. Length;
Read the JPEG file
byte []img = new Byte[size];
System.IO.FileStream fs = new System.IO.FileStream (Imgfilename, System.IO.FileMode.Open);
System.IO.BinaryReader br = new System.IO.BinaryReader (FS);
img = br. Readbytes (size);
Br. Close ();
Note that the BinHex code is used here.
Axmltextwriter.writebinhex (img,0,size);
Axmltextwriter.writeenddocument ();
}
catch (XmlException Xmle)
{
Response.Write (Xmle.message);
}
Finally
{
Axmltextwriter.close ();
}
displaying images
Simply put a PictureBox in the window and write the following code in a button
String xmlfilename = @ "D:\img.xml";
XmlTextReader axmltextreader = new XmlTextReader (XMLfileName);
Axmltextreader.read ();
Axmltextreader.movetocontent ();
if (Axmltextreader.localname = = "JPEG")
{
System.IO.FileInfo fi = new System.IO.FileInfo (xmlfilename);
int isize = (int) fi. Length;
byte []img = new Byte[isize];
Axmltextreader.readbinhex (img,0,isize);
Byte to Image Object
System.IO.MemoryStream ms = new System.IO.MemoryStream ();
Ms. Write (img,0,isize);
Bitmap bmp = new Bitmap (MS);
Ms. Close ();
This.pictureBox1.Image = BMP;
}
Axmltextreader.close ();
Thank you, the author, haha, i "steal" over, easy to see myself;