如何读取xml文件中某节点16进制的图片数据? <Data>424dffffff8effffffd60100000000003600</Data>???这一段,应该是base64编码用byte[] byteimg = System.Convert.FromBase64String( datastring );获取字节流 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 按你上面的写会出现下面的错误啊Base-64 字符数组的无效长度。 已测试可以通过FromBase64String获得byte数组string str = "424dffffff8effffffd60100000000003600";byte[] b = System.Convert.FromBase64String( str );watch:- b {Length=0x1b} byte[] [0x0] 0xe3 byte [0x1] 0x6e byte [0x2] 0x1d byte [0x3] 0x7d byte [0x4] 0xf7 byte [0x5] 0xdf byte [0x6] 0x7d byte [0x7] 0xff byte [0x8] 0x1e byte [0x9] 0x7d byte [0xa] 0xf7 byte [0xb] 0xdf byte [0xc] 0x7d byte [0xd] 0xf7 byte [0xe] 0x7a byte [0xf] 0xd3 byte [0x10] 0x5d byte [0x11] 0x34 byte [0x12] 0xd3 byte [0x13] 0x4d byte [0x14] 0x34 byte [0x15] 0xd3 byte [0x16] 0x4d byte [0x17] 0x34 byte [0x18] 0xdf byte [0x19] 0xad byte [0x1a] 0x34 byte贴出你的代码看看 如果它不是通过base64编码的,这段代码不行,需要了解具体的数据的编码方式,xml内一般只能放置字符串,二进制数据需要编码。 首先谢谢你的帮忙!这部份的代码如下:ImgAuthor = xReader.GetAttribute(0); //ImgAuthor=ImgAuthor.Replace("\r",""); //ImgAuthor = ImgAuthor.Replace("\n", ""); //ImgAuthor = ImgAuthor.Replace("\"", "\\" + "\""); ImgAuthor=DbHelperSQL.InputText(ImgAuthor, 25); Re = xReader.GetAttribute(1); xReader.Read(); if (xReader.Name == "Data") { xReader.Read(); if (xReader.Value != "Unknown") { Docmodel = new PrjPaper.Model.TabDocuments(); Docmodel.Title = Re; Docmodel.DocName = "Img"; Docmodel.DocType = "image/bmp"; //"image/pjpeg"; //string str = xReader.ReadContentAs(typeof(byte[]), null); string str=xReader.ReadContentAsString(); //Docmodel.Contents=xReader.ReadContentAsBase64(typeof(byte[]),0, Docmodel.Contents = System.Convert.FromBase64String(str); //Docmodel.Contents = (byte[])xReader.ReadContentAs(typeof(byte[]), null); //Docmodel.Contents = DbHelperSQL.StringToByte(xReader.ReadContentAs(typeof(string), null)); Docmodel.Author = ImgAuthor; Docmodel.Redate = System.Convert.ToDateTime(SpaceDate); DocID = Docbll.Add(Docmodel); imgmodel.NewsID = newsmodel.ID; imgmodel.ImgDocID = DocID; imgbll.Add(imgmodel); } } Data部份太大,我都贴不出来!我有问了写xml文件的程序员,他说是按16进制写的 vs2010报错 大家好!关于datalist 分页问题,很奇怪!急! winform中为何获取不到选中的CheckBox Socket 封包与拆包的问题?请高手告之,急!! (C#版本)wm5.0的GPS问题,如何将GPS例子中添加海拔和方向的参数? 如何获取图像象素属性(不用生成图像对象) 听说vs2010 Beta 2前两天出来了,vb10和c#已经等同了。 最近DataGrid的问题很多啊,我也碰到一个问题 跪拜“搜索”问题 如何实现textBox内文本自下向上一行一行添加显示? 请问谁能提供一个 fft(快速傅立叶分析) 的类库或函数库,谢谢 关于考试系统自动出题的实现
Base-64 字符数组的无效长度。
string str = "424dffffff8effffffd60100000000003600";
byte[] b = System.Convert.FromBase64String( str );
watch:
- b {Length=0x1b} byte[]
[0x0] 0xe3 byte
[0x1] 0x6e byte
[0x2] 0x1d byte
[0x3] 0x7d byte
[0x4] 0xf7 byte
[0x5] 0xdf byte
[0x6] 0x7d byte
[0x7] 0xff byte
[0x8] 0x1e byte
[0x9] 0x7d byte
[0xa] 0xf7 byte
[0xb] 0xdf byte
[0xc] 0x7d byte
[0xd] 0xf7 byte
[0xe] 0x7a byte
[0xf] 0xd3 byte
[0x10] 0x5d byte
[0x11] 0x34 byte
[0x12] 0xd3 byte
[0x13] 0x4d byte
[0x14] 0x34 byte
[0x15] 0xd3 byte
[0x16] 0x4d byte
[0x17] 0x34 byte
[0x18] 0xdf byte
[0x19] 0xad byte
[0x1a] 0x34 byte贴出你的代码看看
ImgAuthor = xReader.GetAttribute(0);
//ImgAuthor=ImgAuthor.Replace("\r","");
//ImgAuthor = ImgAuthor.Replace("\n", "");
//ImgAuthor = ImgAuthor.Replace("\"", "\\" + "\"");
ImgAuthor=DbHelperSQL.InputText(ImgAuthor, 25);
Re = xReader.GetAttribute(1);
xReader.Read();
if (xReader.Name == "Data")
{
xReader.Read();
if (xReader.Value != "Unknown")
{
Docmodel = new PrjPaper.Model.TabDocuments();
Docmodel.Title = Re;
Docmodel.DocName = "Img";
Docmodel.DocType = "image/bmp"; //"image/pjpeg";
//string str = xReader.ReadContentAs(typeof(byte[]), null);
string str=xReader.ReadContentAsString();
//Docmodel.Contents=xReader.ReadContentAsBase64(typeof(byte[]),0,
Docmodel.Contents = System.Convert.FromBase64String(str);
//Docmodel.Contents = (byte[])xReader.ReadContentAs(typeof(byte[]), null);
//Docmodel.Contents = DbHelperSQL.StringToByte(xReader.ReadContentAs(typeof(string), null));
Docmodel.Author = ImgAuthor;
Docmodel.Redate = System.Convert.ToDateTime(SpaceDate);
DocID = Docbll.Add(Docmodel); imgmodel.NewsID = newsmodel.ID;
imgmodel.ImgDocID = DocID;
imgbll.Add(imgmodel);
}
}