當前位置:首頁 » 服務存儲 » xml存儲圖片鏈接
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

xml存儲圖片鏈接

發布時間: 2022-07-20 17:12:13

① 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進行還原為圖片即可。