星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PrintWindow.xaml.cs 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. using Common.system;
  2. using Spire.Pdf;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Printing;
  8. using System.IO;
  9. using System.Threading;
  10. using System.Windows;
  11. using System.Windows.Input;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Threading;
  14. using TmatrixLibrary;
  15. namespace XHWK.WKTool
  16. {
  17. /// <summary>
  18. /// 打印
  19. /// </summary>
  20. public partial class PrintWindow : Window
  21. {
  22. /// <summary>
  23. /// 下拉框数据源
  24. /// </summary>
  25. public DataTable data = new DataTable();
  26. private DataTable dtComponentsUniqueNo;
  27. private System.Timers.Timer times;
  28. public PrintWindow()
  29. {
  30. InitializeComponent();
  31. double proportion = 1036.0 / 1290.0;
  32. double Widths = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right);
  33. double Heights = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom);
  34. Width = Widths / 1.42;
  35. Height = Heights / 1.71;
  36. GridContent.Width = Width + 5;
  37. GridContent.Height = Height;
  38. ResizeMode = ResizeMode.NoResize;
  39. List<string> defaList = LatticeFileHelper.GetPrinterList(out string defa);
  40. if (defaList.Count > 0)
  41. {
  42. data.Columns.Add("Value");
  43. data.Columns.Add("Key");
  44. for (int i = 0; i < defaList.Count; i++)
  45. {
  46. //创建一行
  47. DataRow row = data.NewRow();
  48. //将此行添加到table中
  49. data.Rows.Add(row);
  50. data.Rows[i]["Value"] = defaList[i];
  51. data.Rows[i]["Key"] = i.ToString();
  52. }
  53. dtComponentsUniqueNo = data.DefaultView.ToTable();
  54. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  55. cmbClass.SelectedIndex = 0;
  56. }
  57. Dictionary<int, int> dicItem = new Dictionary<int, int>();
  58. dicItem.Add(0, 600);
  59. dicItem.Add(1, 1200);
  60. CbxDpi.ItemsSource = dicItem;
  61. CbxDpi.SelectedIndex = 0;
  62. Dictionary<int, string> dictypeItem = new Dictionary<int, string>();
  63. dictypeItem.Add(0, "2x2");
  64. dictypeItem.Add(1, "3x3");
  65. dictypeItem.Add(2, "4x4");
  66. CbxType.ItemsSource = dictypeItem;
  67. CbxType.SelectedIndex = 0;
  68. }
  69. private double wit = 0;
  70. private double hei = 0;
  71. public void Initialize(string _imgPath, double _wit, double _hei)
  72. {
  73. wit = _wit;
  74. hei = _hei;
  75. if (!string.IsNullOrWhiteSpace(_imgPath))
  76. {
  77. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  78. }
  79. else
  80. {
  81. imgPri.Source = null;
  82. }
  83. tip_outer.Visibility = Visibility.Collapsed;
  84. TQLInit();
  85. }
  86. #region TQL打印
  87. /// <summary>
  88. /// 授权文件位置
  89. /// </summary>
  90. string TQLAuthorizationPath;
  91. /// <summary>
  92. /// 授权码
  93. /// </summary>
  94. string gKeyStr;
  95. TmatrixClass TMC = new TmatrixClass();
  96. public static string gPrintFileName;
  97. //string gDirectory = Application.StartupPath;
  98. //string gFileName = "";
  99. bool gbInitDone = false;
  100. //string gUserName = "";
  101. //string gPassword = "";
  102. private string gEKeyStr;
  103. iTextSharp.text.Document document;
  104. enum TMATRIX_POINT_TYPE
  105. {
  106. TmatrixPointType_2x2 = 0, // 2x2 Point Type
  107. TmatrixPointType_3x3 = 1, // 3x3 Point Type
  108. };
  109. enum TMATRIX_OBJECT_TYPE
  110. {
  111. TMATRIX_OT_ElementCode = 0, // 此类型对象的Index范围是:75497472~83886079(十六进制为:0x04800000~0x04ffffff)
  112. TMATRIX_OT_PositionCode, // 此类型对象没有Index
  113. };
  114. /// <summary>
  115. /// 初始化打印
  116. /// </summary>
  117. void TQLInit()
  118. {
  119. ///初始化
  120. if (TMC.TmatrixInitialize() == false)
  121. {
  122. //MessageBox.Show(this, "点阵码初始化失败!", "生成点阵码", MessageBoxButtons.OK, MessageBoxIcon.Error);
  123. //Close();
  124. }
  125. else
  126. {
  127. gbInitDone = true;
  128. }
  129. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  130. try
  131. {
  132. TQLAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
  133. StreamReader gsr = new StreamReader(TQLAuthorizationPath);
  134. gKeyStr = gsr.ReadLine();
  135. gsr.Close();
  136. string KeyCheckResult = TMC.TmatrixKeyCheck_OID4(gKeyStr);
  137. if (KeyCheckResult.Substring(0, 1) == "1")
  138. {
  139. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  140. LogHelper.WriteErrLog("打印服务授权过期:" + KeyCheckResult, null);
  141. gbInitDone = false;
  142. }
  143. else if (KeyCheckResult.Substring(0, 1) == "0")
  144. {
  145. }
  146. }
  147. catch (Exception ex)
  148. {
  149. LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
  150. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  151. gbInitDone = false;
  152. }
  153. }
  154. /// <summary>
  155. /// 铺码
  156. /// </summary>
  157. private bool GenerateCode(string PDFPath)
  158. {
  159. try
  160. {
  161. if (gbInitDone == false)
  162. {
  163. MessageWindow.Show("打印功能无法使用,无效授权。");
  164. return false;
  165. }
  166. try
  167. {
  168. string directoryPath = FileToolsCommon.GetDirectoryName(PDFPath);
  169. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  170. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  171. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  172. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  173. }
  174. catch (Exception)
  175. {
  176. }
  177. int i;
  178. for (i = 0; i < 4; i++)
  179. {
  180. int DPIValue = 0;
  181. int TypeValue = 0;
  182. try
  183. {
  184. DPIValue = CbxDpi.SelectedIndex;
  185. //TypeValue = CbxType.SelectedIndex;
  186. }
  187. catch (Exception)
  188. {
  189. }
  190. APP.gPointType[i] = TypeValue;
  191. APP.gPointDPI[i] = DPIValue;
  192. }
  193. APP.gbGenerateBGWithVImage = false;
  194. APP.gbGenerateVImage = false;
  195. APP.gbGenerateBGWithoutVImage = false;
  196. APP.gbGenerateBGWithImage = true;
  197. //初始页
  198. int SPID = 0;
  199. //int PointType = (int)(TMATRIX_POINT_TYPE.TmatrixPointType_3x3);
  200. //string sGenerateResult = TMC.GenerateTmatrixCode(gKeyStr, PDFFileName, SPID, PointType, GlobalClass.gbGenerateBGWithVImage, GlobalClass.gbGenerateVImage, GlobalClass.gbGenerateBGWithoutVImage, GlobalClass.gbGenerateBGWithImage);
  201. bool[] bPublishImageType = new bool[4];
  202. bPublishImageType[0] = APP.gbGenerateBGWithVImage;
  203. bPublishImageType[1] = APP.gbGenerateVImage;
  204. bPublishImageType[2] = APP.gbGenerateBGWithoutVImage;
  205. bPublishImageType[3] = APP.gbGenerateBGWithImage;
  206. PDFPath = PDFPath.Replace("/", "\\");
  207. string sGenerateResult = TMC.GenerateTmatrixCode_OID4(gKeyStr, PDFPath, SPID, APP.gPointType, bPublishImageType, APP.gPointDPI);
  208. if (sGenerateResult.Substring(0, 1) == "1")
  209. {
  210. Dispatcher.Invoke(() =>
  211. {
  212. MessageWindow.Show("打印功能无法使用,无效授权。");
  213. });
  214. return false;
  215. }
  216. else if (sGenerateResult.Substring(0, 1) == "0")
  217. {
  218. //生成成功
  219. //打印
  220. //Dispatcher.Invoke(() =>
  221. //{
  222. //});
  223. }
  224. return true;
  225. }
  226. catch (Exception ex)
  227. {
  228. Dispatcher.Invoke(() =>
  229. {
  230. MessageWindow.Show("打印失败:" + ex.Message);
  231. });
  232. return false;
  233. }
  234. }
  235. #endregion
  236. /// <summary>
  237. /// 打印
  238. /// </summary>
  239. /// <param name="sender"></param>
  240. /// <param name="e"></param>
  241. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  242. {
  243. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  244. {
  245. MessageWindow.Show("请设置打印机!");
  246. return;
  247. }
  248. btnClose.IsEnabled = false;
  249. btnPrint.IsEnabled = false;
  250. Thread myThread = new Thread(StartPrint);
  251. List<string> StrList = new List<string>();
  252. int ipdf = 102;
  253. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  254. string tempImgPath = imgPath;
  255. imgPath += "101.pdf";
  256. while (File.Exists(imgPath))
  257. {
  258. imgPath = tempImgPath + ipdf.ToString() + ".pdf";
  259. ipdf++;
  260. }
  261. StrList.Add(imgPath);
  262. //打印数量
  263. int PrinterNum = Convert.ToInt32(txbNumberOfCopies.Text);
  264. StrList.Add(PrinterNum.ToString());
  265. //打印机名称
  266. string PrinterName = cmbClass.Text;
  267. StrList.Add(PrinterName);
  268. num = 0;
  269. tip_outer.Visibility = Visibility.Visible;
  270. myThread.Start(StrList);
  271. times = new System.Timers.Timer(100);
  272. times.Elapsed += Times_ElapsedClick;
  273. times.Start();
  274. }
  275. private int num = 0;
  276. /// <summary>
  277. /// 计时器
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  282. {
  283. Dispatcher.Invoke(() =>
  284. {
  285. pgbProcess.Value = num;
  286. lbProcess.Content = num.ToString() + "%";
  287. if (num < 99)
  288. {
  289. num++;
  290. times.Interval += (num / 2);
  291. }
  292. else
  293. {
  294. times.Stop();
  295. }
  296. });
  297. }
  298. /// <summary>
  299. /// 开始打印
  300. /// </summary>
  301. private void StartPrint(object obj)
  302. {
  303. try
  304. {
  305. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f);
  306. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  307. ////设置纸张横向
  308. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  309. List<string> objStr1 = (List<string>)obj;
  310. string SourcePath1 = objStr1[0];
  311. try
  312. {
  313. SourcePath1 = SourcePath1.Replace("/", "\\");
  314. FileStream fs = new FileStream(SourcePath1, FileMode.Create, FileAccess.ReadWrite);
  315. document.AddAuthor("星火微课");//作者
  316. document.AddCreationDate();//创建时候
  317. document.AddCreator("星火微课");//创建者
  318. document.AddSubject("点阵文件");//主题
  319. document.AddTitle("PrintTmatrixCode");//标题
  320. document.AddKeywords("Print");
  321. document.AddHeader("TmatrixCode", "0");
  322. Thread.Sleep(300);
  323. //iTextSharp.text.pdf.PdfDocument pdfDocument = new iTextSharp.text.pdf.PdfDocument();
  324. //document.AddDocListener(pdfDocument);
  325. //iTextSharp.text.pdf.PdfWriter pdfWriter = new iTextSharp.text.pdf.PdfWriter(pdfDocument, fs);
  326. //pdfDocument.AddWriter(pdfWriter);
  327. iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
  328. }
  329. catch (Exception)
  330. {
  331. }
  332. document.Open();
  333. iTextSharp.text.Image image;
  334. for (int i = 0; i < APP.PageDrawList.Count; i++)
  335. {
  336. long ii = Timestamp();
  337. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  338. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  339. RectangleF rectangleFs = new RectangleF();
  340. MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
  341. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  342. if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  343. {
  344. }
  345. else if (APP.PageDrawList[i].ImgDocumentation == true && !APP.PageDrawList[i].Type.Equals("ppt"))
  346. {
  347. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  348. }
  349. else
  350. {
  351. RectangleF rectangleF = new RectangleF(0, 0, 0, 0);
  352. Dispatcher.Invoke(() =>
  353. {
  354. rectangleF = new RectangleF
  355. {
  356. Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  357. Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  358. X = (float)APP.PageDrawList[i].ImageLocation.X,
  359. Y = (float)APP.PageDrawList[i].ImageLocation.Y
  360. };
  361. });
  362. string msgs = string.Empty;
  363. bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msgs);
  364. if (isImg)
  365. {
  366. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  367. }
  368. else
  369. {
  370. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  371. }
  372. }
  373. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  374. {
  375. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  376. }
  377. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  378. {
  379. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  380. }
  381. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  382. document.NewPage();
  383. document.Add(image);
  384. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  385. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  386. //p1.Leading = 150; //行间距
  387. //document.Add(p1);
  388. }
  389. //Console.WriteLine("转换成功!");
  390. document.Close();
  391. }
  392. catch (Exception ex)
  393. {
  394. Dispatcher.Invoke(() =>
  395. {
  396. btnClose.IsEnabled = true;
  397. btnPrint.IsEnabled = true;
  398. times.Stop();
  399. tip_outer.Visibility = Visibility.Collapsed;
  400. MessageWindow.Show(ex.Message);
  401. return;
  402. });
  403. LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
  404. }
  405. List<string> objStr = (List<string>)obj;
  406. //PDF位置
  407. string SourcePath = objStr[0];
  408. int PrinterNum = int.Parse(objStr[1]);
  409. string PrinterName = objStr[2];
  410. Thread.Sleep(500);
  411. //腾千里生成点阵文件
  412. if (GenerateCode(SourcePath))
  413. {
  414. //打印机名称
  415. string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
  416. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  417. try
  418. {
  419. foreach (string fileName in strs)
  420. {
  421. Print(fileName, PrinterName, (short)PrinterNum);
  422. }
  423. }
  424. catch (Exception ex)
  425. {
  426. Dispatcher.Invoke(() =>
  427. {
  428. MessageWindow.Show("打印失败:" + ex.Message);
  429. btnClose.IsEnabled = true;
  430. btnPrint.IsEnabled = true;
  431. times.Stop();
  432. tip_outer.Visibility = Visibility.Collapsed;
  433. return;
  434. });
  435. }
  436. Dispatcher.Invoke(() =>
  437. {
  438. btnClose.IsEnabled = true;
  439. btnPrint.IsEnabled = true;
  440. num = 99;
  441. times.Stop();
  442. pgbProcess.Value = 100;
  443. lbProcess.Content = "100%";
  444. tip_outer.Visibility = Visibility.Collapsed;
  445. MessageWindow.Show("已加入打印机队列,打印中。");
  446. ////打印机名称
  447. //string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
  448. //string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  449. //foreach (string fileName in strs)
  450. //{
  451. // pdfPrint(directoryPath, PrinterName);
  452. //}
  453. //MessageWindow.Show("生成点阵文件成功!");
  454. //string TPFPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  455. //FileToolsCommon.CreateDirectory(TPFPath);
  456. });
  457. }
  458. else
  459. {
  460. Dispatcher.Invoke(() =>
  461. {
  462. btnClose.IsEnabled = true;
  463. btnPrint.IsEnabled = true;
  464. times.Stop();
  465. tip_outer.Visibility = Visibility.Collapsed;
  466. return;
  467. });
  468. }
  469. #region 拓思德生成点阵文件
  470. ////TPF文件位置
  471. //string TPFPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  472. //FileToolsCommon.CreateDirectory(TPFPath);
  473. //TPFPath += "101.TPF";
  474. ////生成点阵文件
  475. //LatticeFileHelper.GeneratingPDF(SourcePath, TPFPath, out int pr, out string msg, out string outPut/*, pyte*/);
  476. //while (!FileToolsCommon.IsExistFile(TPFPath))
  477. //{
  478. // Thread.Sleep(100);
  479. //}
  480. //while (string.IsNullOrWhiteSpace(pr.ToString()))
  481. //{
  482. // Thread.Sleep(100);
  483. //}
  484. //Thread.Sleep(1000);
  485. #endregion
  486. #region 拓思德打印
  487. ////打印
  488. //LatticeFileHelper.PrinterTPFFile(TPFPath, PrinterNum, PrinterName, out int printResult, out string standardError, out string standardOutput);
  489. //if (printResult == 0)
  490. //{
  491. // Dispatcher.Invoke(() =>
  492. // {
  493. // btnClose.IsEnabled = true;
  494. // btnPrint.IsEnabled = true;
  495. // num = 99;
  496. // times.Stop();
  497. // pgbProcess.Value = 100;
  498. // lbProcess.Content = "100%";
  499. // MessageWindow.Show("打印成功!");
  500. // tip_outer.Visibility = Visibility.Collapsed;
  501. // });
  502. //}
  503. //else
  504. //{
  505. // Dispatcher.Invoke(() =>
  506. // {
  507. // btnClose.IsEnabled = true;
  508. // btnPrint.IsEnabled = true;
  509. // times.Stop();
  510. // tip_outer.Visibility = Visibility.Collapsed;
  511. // MessageWindow.Show(standardError);
  512. // });
  513. //}
  514. #endregion
  515. }
  516. /// <summary>
  517. /// 调用打印机打印
  518. /// </summary>
  519. /// <param name="PDFPath">PDF文件路径</param>
  520. /// <param name="PrinterName">打印机名称</param>
  521. void Print(string PDFPath, string PrinterName, short PrinterNum = 1)
  522. {
  523. //加载PDF文档
  524. PdfDocument doc = new PdfDocument();
  525. doc.LoadFromFile(PDFPath);
  526. //指定打印机
  527. doc.PrintSettings.PrinterName = PrinterName;
  528. //静默打印PDF文档
  529. doc.PrintSettings.PrintController = new StandardPrintController();
  530. ////设置文档打印页码范围
  531. //doc.PrintSettings.SelectPageRange(1, 5);
  532. //打印不连续的页面
  533. //doc.PrintSettings.SelectSomePages(new int[] { 1, 3, 5, 7 });
  534. //设置打印份数为2份
  535. doc.PrintSettings.Copies = PrinterNum;
  536. //打印PDF文档
  537. doc.Print();
  538. }
  539. /// <summary>
  540. /// 返回一个时间戳到毫秒
  541. /// </summary>
  542. /// <returns></returns>
  543. public static long Timestamp()
  544. {
  545. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  546. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  547. return timestr;
  548. }
  549. /// <summary>
  550. /// 生成图片
  551. /// </summary>
  552. /// <param name="_path">图片地址</param>
  553. /// <param name="_saveimg">保存位置</param>
  554. /// <param name="_rectangle">图片位置</param>
  555. /// <param name="errmsg">错误消息</param>
  556. /// <returns></returns>
  557. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  558. {
  559. errmsg = null;
  560. try
  561. {
  562. Bitmap bitmap = null;
  563. //创建要显示的图片对象,根据参数的个数设置宽度
  564. Bitmap backgroudImg = new Bitmap((int)/*gridM.ActualWidth*/wit, (int)/*gridM.ActualHeight*/hei);
  565. Graphics g = Graphics.FromImage(backgroudImg);
  566. //清除画布,背景设置为白色
  567. g.Clear(System.Drawing.Color.White);
  568. if (!string.IsNullOrWhiteSpace(_path))
  569. {
  570. bitmap = ImageHelper.ReadBitmapFile(_path);
  571. g.DrawImage(bitmap, _rectangle);
  572. }
  573. #region 添加箭头
  574. string Str = "↑";
  575. SolidBrush mybrush = new SolidBrush(Color.Black); //设置默认画刷颜色
  576. Font myfont = new Font("黑体", 14); //设置默认字体格式
  577. g.DrawString(Str, myfont, mybrush, new Rectangle((int)wit - 50, 20, 50, 50));
  578. #endregion
  579. backgroudImg.Save(_saveimg);
  580. g.Dispose();
  581. backgroudImg.Dispose();
  582. if (bitmap != null)
  583. {
  584. bitmap.Dispose();
  585. }
  586. GC.Collect();
  587. return true;
  588. }
  589. catch (Exception ex)
  590. {
  591. errmsg = ex.Message;
  592. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  593. return false;
  594. }
  595. }
  596. /// <summary>
  597. /// 窗口移动
  598. /// </summary>
  599. /// <param name="sender"></param>
  600. /// <param name="e"></param>
  601. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  602. {
  603. DragMove();
  604. }
  605. /// <summary>
  606. /// 关闭
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. private void BtnClose_Click(object sender, RoutedEventArgs e)
  611. {
  612. Hide();
  613. TMC.TmatrixUninitialize();
  614. }
  615. /// <summary>
  616. /// 减
  617. /// </summary>
  618. /// <param name="sender"></param>
  619. /// <param name="e"></param>
  620. private void BtnLess_Click(object sender, RoutedEventArgs e)
  621. {
  622. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  623. if (num > 1)
  624. {
  625. num--;
  626. txbNumberOfCopies.Text = num.ToString();
  627. }
  628. }
  629. /// <summary>
  630. /// 新增
  631. /// </summary>
  632. /// <param name="sender"></param>
  633. /// <param name="e"></param>
  634. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  635. {
  636. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  637. if (num > 0)
  638. {
  639. num++;
  640. txbNumberOfCopies.Text = num.ToString();
  641. }
  642. }
  643. /// <summary>
  644. /// 打印说明
  645. /// </summary>
  646. /// <param name="sender"></param>
  647. /// <param name="e"></param>
  648. private void btnPrintExplain_Click(object sender, RoutedEventArgs e)
  649. {
  650. System.Diagnostics.Process.Start(FileToolsCommon.GetFileAbsolutePath("/星火微课点阵码打印及印刷指导手册.docx"));
  651. }
  652. }
  653. }