① c# 图片如何保存到xml文件
首先我们做些准备工作:
1.在c盘下创建一个文件夹并命名为picture。里面存放一张图片(任意格式的一张)。c:/picture/001.jpg
2.在c盘下创建一个文件夹并命名为picture2.里面存放一个xml文件。c:/picture1/11.xml
在xml文件中加一个根节点(这里是为了操作的方便直接在文件中添加的,你也可以在你的代码中动态的添 加)如<picture</picture
接下来的程序就是实现将图片001.jpg通过base64编码后储存到11.xml文件中。
先在form中拖进一个button。双击触发click事件。事件代码如下:View Code1usingSystem;2usingSystem.Collections.Generic;3usingSystem.ComponentModel;4usingSystem.Data;5usingSystem.Drawing;6usingSystem.Linq;7usingSystem.Text;8usingSystem.Windows.Forms;9usingSystem.IO;10usingSystem.Xml;11namespace图片存储xml文件12{13publicpartialclassForm1 : Form14{15publicForm1()16{17InitializeComponent();18}192021privatevoidbutton1_Click(objectsender, EventArgs e)22{23try24{25XmlDocument myxmldoc =newXmlDocument();26myxmldoc.Load(
C:/picture1/11.xml);27XmlElement elem = myxmldoc.createElement_x(image);28//打开图片文件,利用该图片构造一个文件流29FileStream fs =newFileStream(
C:/picture/001.jpg
, FileMode.Open);30//使用文件流构造一个二进制读取器将基元数据读作二进制值31BinaryReader br =newBinaryReader(fs);32byte[] imagebuffer =newbyte[br.BaseStream.Length];33br.Read(imagebuffer,0
,Convert.ToInt32(br.BaseStream.Length));34stringtextstring =
System.Convert.ToBase64String(imagebuffer);35fs.Close();36br.Close();37XmlText text =
myxmldoc.CreateTextNode(textstring);38myxmldoc.DocumentElement.AppendChild(elem);39myxmldoc.DocumentElement.LastChild.AppendChild(text);404142myxmldoc.Save(
C:/picture1/11.xml);434445MessageBox.Show(读写结束!);46}47catch(Exception ex)48{49MessageBox.Show(ex.ToString());50}51}52}53}运行后打开c盘下的picture1文件夹,双击11.xml文件。看到里面除了你开始添加的picture标签以外还多出了image标签,标签里面都是你看不懂的字母。说明你已经转换成功了。
② c#中如何用XML文件保存、读取图片
不复杂的,把图片转换为二进制数组,然后序列为Base64字符串,并保存到XML节点中如果有必要的话,请注明此数据块是什么类型的图片,比如"jpeg"这样有助于反序列化回来.比如你是icon,但写在jpeg,在转换回来的时候就会有问题,
③ XML中给图片加链接格式怎么写
嗯 我就是想知道这个输出的格式应该怎么写,这样PHP程序可以根据格式输出生成XML数据格式还是要改FLASH源文件代码读取啊? 要对应?
④ 易语言怎么将图片储存到.XMl文件和从XML中读取图片显现出来
啊,不错啊提交回答
⑤ 如何把一个图像存储到XML数据中,并读取出来
//定义图像源与目标xml文件
string ImgFileName = @"d:\ 告.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");
//下边就是通用的读取图像的代码
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();
//注意这里用的是BinHex编码
aXmlTextWriter.WriteBinHex(img,0,size);
aXmlTextWriter.WriteEndDocument();
}
catch(XmlException xmlE)
{
Response.Write(xmlE.Message);
}
finally
{
aXmlTextWriter.Close();
}
显示图像
简单的在窗口中放一个PictureBox,在一个按钮中写如下代码
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();
⑥ as3.0做随机相册,图片链接写在xml里,点击图片链接到指定网址。试了几次都链接到本地的文件夹。不知咋弄
访问Internet网址,一律必须加http://,任何编程语言都是这样识别的。
你不加,as3会以为是本地的一个相对路径。
⑦ 关于flash XML加载图片,怎么样可以在图片上加超链接
for (var d:Number = 0; d<sizPage_num; d++) {
if (_page*sizPage_num+d>=url_array.length) {
break;
}
_mcl.loadClip(url_array[_page*sizPage_num+d], this["pic_mc"+d]); }};
把链接加到这个循环里就可以了。如下:
for (var d:Number = 0; d<sizPage_num; d++) {
if (_page*sizPage_num+d>=url_array.length) {
break;
}
_mcl.loadClip(url_array[_page*sizPage_num+d], this["pic_mc"+d]);
this["pic_mc"+d].onPress=function()
{
var str=this._name.slice(6);
getURL(url[_page*sizPage_num+d],"_blank");//这里的url是要先定义一个数组,用于存储图片的链接,因为每个图片的超链接肯定不一样的。这些可以同时写到XML文件里然后进行读取
}
}};
⑧ 如何在xml中给图片加个链接!急
你是大菜鸟?
xml是数据存储的啊.
你存上这个图片相应的连接就可以了啊.
<folio>
<image>
<thumbnail>./images/3s.jpg</thumbnail>
<pic>./images/3.jpg</pic>
<link>www.sina.com</link>
</image>
</folio>
只有在读出这些数据的代码中读出来才能加到相应的图片上啊
⑨ Java中如何把图片数据存储到xml中及把存储在xml中的图片信息读取出来显示到浏览器中
读取到的byte[]的图片,进行base64编码成一个字符串,存到一个xml中。读取的时候对这个base64进行还原为图片即可。