In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to download local pictures from the server and display them in the Image control. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Query the three kinds of pictures on the server according to the picture name, and then display them on the corresponding Image controls in turn.
Using System;using System.Drawing;using System.Collections;using System.ComponentModel;using DevExpress.XtraReports.UI;using System.Data;using TRSCore;using System.Text;using MESCore;using DevExpress.DataAccess.EntityFramework;using System.Collections.Generic;using System.Windows.Forms;using System.IO;using Neodynamic.SDK.Printing;namespace QCMCore.Reports {public partial class rptQCMCOACard: DevExpress.XtraReports.UI.XtraReport {public rptQCMCOACard () {InitializeComponent () } public rptQCMCOACard (DataTable dt,string sBatchID,string sModelID) {InitializeComponent (); this.dtOrd = dt; this.sBatchID = sBatchID; this.sModelID = sModelID;} DataTable dtOrd = new DataTable (); DataSet ds = new DataSet (); string sBatchID = "; string sModelID =" String sImage1 = ""; string sImage2 = ""; string sImage3 = ""; private bool View_Iamges () {TRSNode in_node = new TRSNode ("View_Label_In"); TRSNode out_node = new TRSNode ("View_Label_Out"); try {sImage1 = "Picture 1-1.png" SImage2 = "Picture 3-1.png"; sImage3 = "Picture 2.png"; List Imagelist = new List (); List xrImagelist = new List (); xrImagelist.Add (xrPictureBox1); xrImagelist.Add (xrPictureBox2); xrImagelist.Add (xrPictureBox3); Imagelist.Add (sImage1) Imagelist.Add (sImage2); Imagelist.Add (sImage3); if (Imagelist! = null & & Imagelist.Count > 0) {for (int I = 0; I)
< Imagelist.Count; i++) { if (Imagelist[i] != "") { //open a thermal label template // string filePath = Application.StartupPath + "\\UserFile\\Label\\" + sLastSaveFile; #region 服务器文件下载 in_node = new TRSNode("View_File_In"); out_node = new TRSNode("Cmn_Out"); CommonRoutine.SetInMsg(in_node); in_node.ProcStep = '2'; in_node.AddString("FILENAME", CommonFunction.Trim(Imagelist[i])); if (CommonRoutine.CallService("BAS", "BAS_View_File", in_node, ref out_node) == false) { return false; } #endregion byte[] bytearay = CommonFunction.RemoveByteOrderMark(out_node.GetBlob("FILEDATA")); if (bytearay != null) { MemoryStream ms_buffer; try { ms_buffer = new MemoryStream(); //对于要重复使用缓存而不是保存到本地再引用,避免报错:图片已被另一进程中使用 ms_buffer.Write(bytearay, 0, bytearay.Length); ms_buffer.Position = 0; xrImagelist[i].Image = null; // xrImagelist[i].Image = Image.FromStream(ms_buffer); string filedata = System.Text.Encoding.Default.GetString(bytearay); } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); } } } } return true; } else { return false; } } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } private bool FillHeader() { try { if (dtOrd == null) { CommonFunction.ShowMsgBox("请先选择需要打印的ITEM!"); return false; } this.xrtBatchID.Text = sBatchID; this.xrtModel.Text = sModelID; if (View_Iamges()==false ) { CommonFunction.ShowMsgBox("图片找不到!"); return false; } //this.xrPictureBox1.ImageUrl = Application.StartupPath + "\\UserFile\\Images\\图片1-1.png"; //this.xrPictureBox2.ImageUrl = Application.StartupPath + "\\UserFile\\Images\\图片3-1.png"; //this.xrPictureBox3.ImageUrl = Application.StartupPath + "\\UserFile\\Images\\图片2.png"; this.xrtDateTime.Text = DateTime.Now.ToShortDateString().ToString(); // 20018-9-4 if (dtOrd.Rows.Count >0) {ds.Clear (); ds.Tables.Add (dtOrd.Copy ()); / / use Copy's Table to avoid error reports: DataTable already has another DataSet XtraReport report = new XtraReport (); report.DataSource = ds; report.DataMember = "queryProducts" List list = new List (); for (int I = 0; I
< dtOrd.Rows.Count;i++) { DataTable dt = new DataTable(); dt.Columns.Add("ITEM_SEQ"); dt.Columns.Add("TESTING_ITEM"); dt.Columns.Add("TESTING_RESULT"); dt.Columns.Add("TESTING_SPECIFICATION"); dt.Columns.Add("DIMENS"); dt.Columns.Add("TESTING_METHOD"); dt.Rows.Add(dtOrd.Rows[i].ItemArray); list.Add(dt); } XRTable table = new XRTable(); for (int i = 0; i < dtOrd.Rows.Count; i++) { if (list[i]!=null) { XRTableRow row = new XRTableRow(); XRTableCell TESTING_ITEM = new XRTableCell(); XRTableCell TESTING_RESULT = new XRTableCell(); XRTableCell TESTING_SPECIFICATION = new XRTableCell(); XRTableCell DIMENS = new XRTableCell(); XRTableCell TESTING_METHOD = new XRTableCell(); row.Cells.Add(TESTING_ITEM); row.Cells.Add(TESTING_RESULT); row.Cells.Add(TESTING_SPECIFICATION); row.Cells.Add(DIMENS); row.Cells.Add(TESTING_METHOD); //TESTING_ITEM.WidthF = 140.14f; //TESTING_RESULT.WidthF = 140.14f; //TESTING_SPECIFICATION.WidthF = 140.14f; //DIMENS.WidthF = 140.14f; //TESTING_METHOD.WidthF = 140.14f; TESTING_ITEM.DataBindings.Add("Text", list[i], "TESTING_ITEM"); TESTING_RESULT.DataBindings.Add("Text", list[i], "TESTING_RESULT"); TESTING_SPECIFICATION.DataBindings.Add("Text", list[i], "TESTING_SPECIFICATION"); DIMENS.DataBindings.Add("Text", list[i], "DIMENS"); TESTING_METHOD.DataBindings.Add("Text", list[i], "TESTING_METHOD"); xrTable7.Rows.Add(row); //xrTable7.InsertRowBelow(xrTable7.Rows[i]); } } DetailBand detailBand = new DetailBand(); detailBand.Controls.Add(table); report.Bands.Add(detailBand); } return true; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } private void ReportHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { FillHeader(); } }} =========初试代码有bug private bool View_Iamges() { TRSNode in_node = new TRSNode("View_Label_In"); TRSNode out_node = new TRSNode("View_Label_Out"); try { sImage1 = "图片1-1.png"; sImage2 = "图片3-1.png"; sImage3 = "图片2.png"; List Imagelist = new List(); Imagelist.Add(sImage1); Imagelist.Add(sImage2); Imagelist.Add(sImage3); if (Imagelist != null && Imagelist.Count >0) {for (int I = 0; I
< Imagelist.Count; i++) { if (Imagelist[i] != "") { //open a thermal label template // string filePath = Application.StartupPath + "\\UserFile\\Label\\" + sLastSaveFile; #region 服务器文件下载 in_node = new TRSNode("View_File_In"); out_node = new TRSNode("Cmn_Out"); CommonRoutine.SetInMsg(in_node); in_node.ProcStep = '2'; //查询对应的文件夹 in_node.AddString("FILENAME", CommonFunction.Trim(Imagelist[i])); if (CommonRoutine.CallService("BAS", "BAS_View_File", in_node, ref out_node) == false) { return false; } #endregion byte[] bytearay = CommonFunction.RemoveByteOrderMark(out_node.GetBlob("FILEDATA")); if (bytearay != null) { string filedata = System.Text.Encoding.Default.GetString(bytearay); //保存Label文件到本地,进行编辑 string filePath = Application.StartupPath + "\\UserFile\\Images\\" + Imagelist[i]; File.WriteAllBytes(filePath, bytearay); string picPath = filePath.Substring(0, filePath.Length - 4) + ".png";//本地Label图片路径 if (!File.Exists(picPath))//如果图片不存在,生成 { ThermalLabel tl = ThermalLabel.CreateFromXmlTemplate(filedata); //Display ThermalLabel as a TIFF image if (tl != null) { //替换DataField,使其显示 foreach (Item item in tl.Items) { if (item.DataField != "") { item.DataField = "";//必须置为空,否则无法显示 } } using (PrintJob pj = new PrintJob()) { pj.ThermalLabel = tl; pj.Copies = 1; MemoryStream ms = new MemoryStream(); ImageSettings imgSett = new ImageSettings(); imgSett.ImageFormat = Neodynamic.SDK.Printing.ImageFormat.Png; //imgSett.PixelFormat = PixelFormat.BGRA32; imgSett.AntiAlias = true; //imgSett.TransparentBackground = true; pj.ExportToImage(picPath, imgSett, 300); } } } //在对应的控件中显示 if (i == 0) xrPictureBox1.Image = Image.FromFile(picPath); if (i == 1) xrPictureBox2.Image = Image.FromFile(picPath); if (i == 2) xrPictureBox3.Image = Image.FromFile(picPath); } } } return true; } return false; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } 注: 1、当所用的图片需要被重复引用时,将图片从服务端下载至本地再引用的做法容易报错:图片正由另一个进程使用。The solution is to remember to release resources when using the File.WriteAllBytes () method.
The second is to use memory to fill the picture directly into the control, instead of downloading the picture to the client and then filling it.
MemoryStream ms_buffer; try {ms_buffer = new MemoryStream () / / avoid reporting errors if you want to reuse the cache instead of saving it locally to re-reference: the picture has been used by ms_buffer.Write (bytearay, 0, bytearay.Length) in another process; ms_buffer.Position = 0; xrImagelist [I] .image = null / / xrImagelist [I] .image = Image.FromStream (ms_buffer); string filedata = System.Text.Encoding.Default.GetString (bytearay) } catch (Exception ex) {CommonFunction.ShowMsgBox (ex.Message);}
2. When the passed DataTable is reused, it is easy to report an error: DataTable already belongs to another DataSet.
The solution is to add cloned or copied tables to DataSet.
Ds.Tables.Add (dtOrd.Copy ()); on how to download the local picture from the server and display it in the Image control, that's it. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.