利用水晶报表显示二进制形式的图片,在博客园中也找到阿泰的做法,直接转换成二进制字段,而且在水晶报表里拖进去,但就是不显示,有没有遇到过相似问题的,希望能帮助解答一下,多谢
1 DataTable dt = new DataTable();
2 dt.TableName = "TRANSFORMERINFO";
3 dt.Columns.Add(new DataColumn("TransformerID", typeof(string)));
4 dt.Columns.Add(new DataColumn("TransformerName", typeof(string)));
5 dt.Columns.Add(new DataColumn("TransCode", typeof(string)));
6 dt.Columns.Add(new DataColumn("TransTypeName", typeof(string)));
7 // dt.Columns.Add(new DataColumn("CreateDateTime", typeof(string)));
8 dt.Columns.Add(new DataColumn("Manufacturer", typeof(string)));
9 dt.Columns.Add(new DataColumn("TransModel", typeof(string)));
10 dt.Columns.Add(new DataColumn("PositionName", typeof(string)));
11 dt.Columns.Add(new DataColumn("Capacity", typeof(string)));
12 dt.Columns.Add(new DataColumn("HighVoltage", typeof(string)));
13 dt.Columns.Add(new DataColumn("TotalWeight", typeof(string)));
14 dt.Columns.Add(new DataColumn("TransSize", typeof(string)));
15 dt.Columns.Add(new DataColumn("RelayCount", typeof(string)));
16 dt.Columns.Add(new DataColumn("MasterSwitchModel", typeof(string)));
17 dt.Columns.Add(new DataColumn("RelayModel", typeof(string)));
18 dt.Columns.Add(new DataColumn("ContactorModel", typeof(string)));
19 dt.Columns.Add(new DataColumn("SafetySwitchModel", typeof(string)));
20 dt.Columns.Add(new DataColumn("DisplayCT", typeof(string)));
21 dt.Columns.Add (new DataColumn("ImageByte",typeof(byte[])));
22 dt.Columns.Add(new DataColumn("Longitude", typeof(string)));
23 dt.Columns.Add(new DataColumn("Latitude", typeof(string)));
24 dt.Columns.Add(new DataColumn("Address", typeof(string)));
25 dt.Columns.Add(new DataColumn("CantonCode", typeof(string)));
26 dt.Columns.Add(new DataColumn("TransformerIntro", typeof(string)));
27 DataRow row = null;
28 row = dt.NewRow();
29 row["TransformerID"] = transformer.TransformerID;
30 row["TransformerName"] = transformer.TransformerName;
31 row["TransCode"] = transformer.TransCode;
32 row["TransTypeName"] = transformer.TransTypeName;
33 row["Manufacturer"] = transformer.Manufacturer;
34 //row["CreateDateTime"] = transformer.CreateDateTime;
35 row["TransModel"] = transformer.TransModel;
36 row["PositionName"] = transformer.PositionName;
37 row["Capacity"] = transformer.Capacity;
38 row["HighVoltage"] = transformer.HighVoltage;
39 row["TotalWeight"] = transformer.TotalWeight;
40 row["TransSize"] = transformer.TransSize;
41 row["RelayCount"] =transformer.RelayCount;
42 row["MasterSwitchModel"] =transformer.MasterSwitchModel;
43 row["RelayModel"] = transformer.RelayModel;
44 row["ContactorModel"] = transformer.ContactorModel;
45 row["SafetySwitchModel"] = transformer.SafetySwitchModel;
46 row["DisplayCT"] = transformer.DisplayCT;
47 row["Longitude"] = transformer.Longitude;
48 row["Latitude"] = transformer.Latitude;
49 row["Address"] = transformer.Address ;
50 row["CantonCode"] = transformer.CantonCode;
51 row["TransformerIntro"] = transformer.TransformerIntro;
52 #region 获取图片二进制流
53 if (ImgTranFiles.Count == 0) return;
54 string LocalImagePath = this.imageUploader.GetLocalImagePath(ImageType .Transformer);
55
56 //判断根目录是否存在
57 if (!Directory.Exists(this.imageUploader.LocalImagePath))
58 {
59 Directory.CreateDirectory(this.imageUploader.LocalImagePath);
60 }
61 //判断二级目录是否存在
62 if (!Directory.Exists(LocalImagePath))
63 {
64 Directory.CreateDirectory(LocalImagePath);
65 }
66 string imagePath = LocalImagePath + "\\" + this._imageUrl;
67 //判断文件是否存在
68 if (File.Exists(imagePath))
69 {
70 //显示图片
71 FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Delete);
72 imgbyte = new byte[fs.Length];
73 fs.Read(imgbyte, 0, imgbyte.Length);
74 }
75 else
76 {
77 //从服务器上取得图片
78 byte[] rbyte = PImageUploader.GetImage(ImageType.Transformer, ImgTranFiles[0].PictureUrl, Program.dbname);
79 imgbyte = new byte[rbyte.Length];
80 imgbyte = rbyte;
81 }
82 #endregion
83 if (imgbyte != null)
84 {
85 row["ImageByte"] = imgbyte;
86 //transformer.ImageByte = imgbyte;
87 }
88 else
89 {
90 byte[] aaa = System.Text.Encoding.Default.GetBytes("4151615616416");
91 row["ImageByte"] = aaa;
92 }
93 dt.Rows.Add(row);
94 dt.AcceptChanges();
95 List<B_Transformer> transformerlist = new List<B_Transformer>();
96 transformerlist.Add(transformer);