public static void ChangeTrainTicketInfo(TrainTicketInfo ticketInfo) { foreach (var item in TrainTickets_Info) { if (item.logid == ticketInfo.logid) { TrainTickets_Info.Remove(item); TrainTickets_Info.Add(ticketInfo); return; } } }
public static TrainTicketInfo GetTrainTicket(string Ticket_logid) { TrainTicketInfo ticketInfo = new TrainTicketInfo(); foreach (var item in TrainTickets_Info) { if (item.logid == Ticket_logid) { ticketInfo = item; } } return(ticketInfo); }
public static TrainTicketInfo AI_TrainTicket(string path) { var Imageinfo = File.ReadAllBytes(path); var result = client.TrainTicket(Imageinfo); TrainTicketInfo Tickinfo = new TrainTicketInfo(); Tickinfo.logid = (string)result["log_id"]; Tickinfo.ticket_num = (string)result["words_result"]["ticket_num"]; Tickinfo.date = (string)result["words_result"]["date"]; Tickinfo.name = FixName((string)result["words_result"]["name"]); Tickinfo.seat_category = (string)result["words_result"]["seat_category"]; Tickinfo.starting_station = (string)result["words_result"]["starting_station"]; Tickinfo.destination_station = (string)result["words_result"]["destination_station"]; Tickinfo.train_num = (string)result["words_result"]["train_num"]; Tickinfo.ticket_rates = (string)result["words_result"]["ticket_rates"]; Tickinfo.jianpiao = String.Format("检票:{0}", TrainTicket.GetRandomLetter().ToString() + new Random().Next(0, 9).ToString()); Random ran = new Random(); int n = ran.Next(10, 24); int n2 = ran.Next(10, 24); Tickinfo.train_starttime = n + ":" + n2; int n3 = ran.Next(1, 9); Tickinfo.train_che = "0" + n3; int n4 = ran.Next(1, 9); Tickinfo.train_hao = "0" + n4 + "B"; Tickinfo.ID = "384951990042215674"; if (People_ID.Contains(GetPeopleID(Tickinfo.name))) { Tickinfo.ID = GetPeopleID(Tickinfo.name).id; } else { Tickinfo.ID = "请手动输入"; } Tickinfo.bottomid = GetRandombottomid(); return(Tickinfo); }
public static void TrainTickets() { JObject result = null; JObject firstresult = null; //预先识别检查是否为一张可以识别的火车票 try { firstresult = client.GeneralBasic(Imageinfo); } catch (Exception e) { MessageBox.Show(string.Format("识别错误{0}", e), "车票识别", MessageBoxButtons.OK, MessageBoxIcon.Error); } var resultnum = (int)firstresult["words_result_num"]; if (resultnum < 15) { OnTrainTicketError(OrinImage); return; } // 调用火车票识别 try { result = client.TrainTicket(Imageinfo); } catch (Exception e) { MessageBox.Show(String.Format("识别车票错误\n错误信息{0}", e), "车票识别", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } var Tickinfo = new TrainTicketInfo { logid = (string)result["log_id"], ticket_num = (string)result["words_result"]["ticket_num"], date = (string)result["words_result"]["date"], name = FixName((string)result["words_result"]["name"]), seat_category = (string)result["words_result"]["seat_category"], starting_station = (string)result["words_result"]["starting_station"], destination_station = (string)result["words_result"]["destination_station"], train_num = (string)result["words_result"]["train_num"], ticket_rates = (string)result["words_result"]["ticket_rates"], jianpiao = String.Format("检票:{0}", TrainTicket.GetRandomLetter().ToString() + new Random().Next(0, 9).ToString()) }; Random ran = new Random(); int n = ran.Next(10, 24); int n2 = ran.Next(10, 24); Tickinfo.train_starttime = n + ":" + n2; int n3 = ran.Next(1, 9); Tickinfo.train_che = "0" + n3; int n4 = ran.Next(1, 9); Tickinfo.train_hao = "0" + n4 + "B"; Tickinfo.ID = "362301998123457130"; if (!String.IsNullOrWhiteSpace(Tickinfo.name)) { if (People_ID.Contains(GetPeopleID(Tickinfo.name))) { Tickinfo.ID = GetPeopleID(Tickinfo.name).id; } else { MessageBox.Show(String.Format("找不到{0}这人的身份证\n请手动添加\n或去设置中的身份证设置中进行添加", Tickinfo.name), "车票识别", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } Tickinfo.bottomid = GetRandombottomid(); OnTrainTicketMaked(Tickinfo); return; }
/// <summary> /// 添加车票信息到图片并存放 /// </summary> /// <param name="tickInfo"></param> public static Image MakeTrainTickImage(TrainTicketInfo tickInfo) { if (tickInfo.logid == null) { return(null); } if (TrainTicket.BaseTicketImage == null) { try { TicketImageTool.LoadAllBaseTrainTicketsImage(); } catch { MessageBox.Show("车票模板为空:" + TrainTicket.BaseTickfilePath + "\n" + "请检查是否含有车票模板", "车票目录", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); System.Diagnostics.Process.Start(TrainTicket.BaseTickfilePath); } return(null); } var ticketnumber = new Random().Next(0, TrainTicket.BaseTicketImage.Count); var image = TrainTicket.BaseTicketImage[ticketnumber]; //Console.WriteLine(image.Width + " " + image.Height); Bitmap bitmap = new Bitmap(image, image.Width, image.Height); Graphics g = Graphics.FromImage(bitmap); //cutImage(image, new Point(136,69),50,30); //字体矩形位置 : //x = 图片的长度的中心位置 - 字体长度的一半 - 字行距 //y = 图片的高度的中心位置 - 字体大小的一半 - 偏移(去掉偏移,是居中位置) string year = null; if (tickInfo.date.Length >= 4) { year = tickInfo.date[0].ToString() + tickInfo.date[1].ToString() + tickInfo.date[2].ToString() + tickInfo.date[3].ToString();//年 } string moth = null; if (tickInfo.date.Length >= 7) { moth = tickInfo.date[5].ToString() + tickInfo.date[6].ToString();//月 } string day = null; if (tickInfo.date.Length >= 10) { day = tickInfo.date[8].ToString() + tickInfo.date[9].ToString();//日 } string fickrates = null; if (tickInfo.ticket_rates.Contains("¥")) { fickrates = tickInfo.ticket_rates.Replace("¥", string.Empty); } string Rates = null; if (fickrates != null && fickrates.Contains("元")) { Rates = fickrates.Replace("元", string.Empty); } string Start_Station = null; string Start_Stationpinyin = null; if (!String.IsNullOrWhiteSpace(tickInfo.starting_station)) { Start_Station = tickInfo.starting_station.Remove(tickInfo.starting_station.Length - 1); Start_Stationpinyin = PingYinHelper.GetPinyin(tickInfo.starting_station.Remove(tickInfo.starting_station.Length - 1)); } string destination_Station = null; string Des_Stationpinyin = null; if (!String.IsNullOrWhiteSpace(tickInfo.destination_station)) { destination_Station = tickInfo.destination_station.Remove(tickInfo.destination_station.Length - 1); Des_Stationpinyin = PingYinHelper.GetPinyin(tickInfo.destination_station.Remove(tickInfo.destination_station.Length - 1)); } string S_station = null; string D_station = null; int S_pinyinaddX = 0; int D_pinyinaddX = 0; int max_pinyinmove_length = 9; bool D_ISLongPinyin = false; bool S_ISLongPinyin = false; if (Start_Stationpinyin != null && Start_Stationpinyin.Length <= max_pinyinmove_length) { S_pinyinaddX = 42 - Start_Stationpinyin.Length; } else { S_ISLongPinyin = true; } if (Des_Stationpinyin != null && Des_Stationpinyin.Length <= max_pinyinmove_length) { D_pinyinaddX = 42 - Des_Stationpinyin.Length; } else { D_ISLongPinyin = true; } if (Start_Station != null && Start_Station.Length <= 2) { S_station += Start_Station[0]; S_station += " "; S_station += Start_Station[1]; } else { S_station = Start_Station; } if (destination_Station != null && destination_Station.Length <= 2) { D_station += destination_Station[0]; D_station += " "; D_station += destination_Station[1]; } else { D_station = destination_Station; } string IDinfo = null; char addidinfo; for (int i = 0; i < tickInfo.ID.Length; i++) { if (i >= 10 && i <= 13) { addidinfo = '*'; } else { addidinfo = tickInfo.ID[i]; } IDinfo += addidinfo; } var reduce = new Random().Next(0, 20); AddInfoToImage(tickInfo.ticket_num, g, 40, "arial.ttf", 50, 35 - reduce, RedBrush, FontStyle.Bold); AddInfoToImage(tickInfo.jianpiao, g, 32, 680, 20, blackBrush); AddInfoToImage(S_station, g, 41, 110, 80, blackBrush); if (Start_Stationpinyin != null) { if (S_ISLongPinyin) { AddInfoToImage(Start_Stationpinyin, g, 30, "标准仿宋体简.ttf", 110 + Start_Stationpinyin.Length + S_pinyinaddX, 140, blackBrush, FontStyle.Regular, 0.8f, 1); } else { AddInfoToImage(Start_Stationpinyin, g, 30, "标准仿宋体简.ttf", 110 + Start_Stationpinyin.Length + S_pinyinaddX, 140, blackBrush); } } AddInfoToImage("站", g, 30, 290, 90, blackBrush); AddInfoToImage(D_station, g, 41, 600, 80, blackBrush); if (Des_Stationpinyin != null) { if (D_ISLongPinyin) { AddInfoToImage(Des_Stationpinyin, g, 30, "标准仿宋体简.ttf", 600 + Des_Stationpinyin.Length + D_pinyinaddX, 140, blackBrush, FontStyle.Regular, 0.8f, 1); } else { AddInfoToImage(Des_Stationpinyin, g, 30, "标准仿宋体简.ttf", 600 + Des_Stationpinyin.Length + D_pinyinaddX, 140, blackBrush); } } AddInfoToImage("站", g, 30, 780, 90, blackBrush); //////////////////////////////////////////////// if (tickInfo.train_num.Length < 4) { AddInfoToImage(tickInfo.train_num, g, 40, "车次.ttf", 400 + 20 - tickInfo.train_num.Length, 80, blackBrush); } else if (tickInfo.train_num.Length == 4) { AddInfoToImage(tickInfo.train_num, g, 40, "车次.ttf", 408, 80, blackBrush); } else if (tickInfo.train_num.Length == 5) { AddInfoToImage(tickInfo.train_num, g, 40, "车次.ttf", 392, 80, blackBrush); } ///////////////////////////////////////////////////////////////// AddInfoToImage(tickInfo.train_che, g, 32, "TechnicBold.ttf", 587, 182, blackBrush); AddInfoToImage("车", g, 20, 637, 195, blackBrush); AddInfoToImage(tickInfo.train_hao, g, 32, "TechnicBold.ttf", 660, 182, blackBrush); AddInfoToImage("号", g, 20, 732, 195, blackBrush); //AddInfoToImage("限乘当日当次车", g, 9, 20, 110, blackBrush); ////////////////////////////////////////////////// AddInfoToImage("网", g, 27, 400, 242, blackBrush); AddInfoToImage(tickInfo.seat_category, g, 25, 642, 240, blackBrush); AddInfoToImage(year, g, 34, "TechnicBold.ttf", 79, 182, blackBrush, FontStyle.Regular); AddInfoToImage("年", g, 20, 170, 195, blackBrush); AddInfoToImage(moth, g, 34, "TechnicBold.ttf", 200, 182, blackBrush, FontStyle.Regular); AddInfoToImage("月", g, 20, 255, 195, blackBrush); AddInfoToImage(day, g, 34, "TechnicBold.ttf", 285, 182, blackBrush, FontStyle.Regular); AddInfoToImage("日", g, 20, 337, 195, blackBrush); AddInfoToImage(tickInfo.train_starttime, g, 34, "TechnicBold.ttf", 376, 182, blackBrush, FontStyle.Bold); AddInfoToImage("开", g, 20, 480, 195, blackBrush); //AddInfoToImage("¥", g, 31, "华文宋体.ttf", 80, 240, blackBrush); AddInfoToImage(Rates, g, 33, "TechnicBold.ttf", 119, 240, blackBrush); int yuan_X = 0; if (Rates != null && Rates.Length > 4) { yuan_X += 25; } AddInfoToImage("元", g, 20, 205 + yuan_X, 250, blackBrush); // AddInfoToImage(tickInfo.ticket_num, g, 13, 20, 9, RedBrush); AddInfoToImage(tickInfo.name, g, 31, 460f, 397f, blackBrush); AddInfoToImage(IDinfo, g, 33.5f, "TechnicBoldshort.ttf", 78f, 397f, blackBrush); //AddInfoToImage(tickInfo.bottomid, g, 25f, 80f, 560f, blackBrush,FontStyle.Bold,1f,2f); AddInfoToImage(tickInfo.bottomid, g, 20f, "仿宋_GB2312.ttf", 90f, 560f, blackBrush, FontStyle.Regular, 1.147f, 1.6f); AddInfoToImage(Start_Station, g, 27f, 440f, 560f, blackBrush, FontStyle.Bold); int Shou_X = 0; if (Start_Station != null && Start_Station.Length <= 2) { Shou_X -= 38; } AddInfoToImage("售", g, 27f, 550f + Shou_X, 560f, blackBrush, FontStyle.Bold); string strCode = string.Format("网络异常\n车票读取信息为{0}\n{1}\n{2}→{3}\n{4}年{5}月{6}日{7}\n{8}车{9}号\n{10}", tickInfo.ticket_num, tickInfo.train_num, S_station, D_station, year, moth, day, tickInfo.train_starttime, tickInfo.train_che, tickInfo.train_hao, tickInfo.name); // string strCode = "https://www.12306.cn/index/"; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); // qrcode.GetGraphic 方法可参考最下发“补充说明” Bitmap qrCodeImage = qrcode.GetGraphic(3, Color.FromArgb(160, 0, 0, 0), Color.FromArgb(0, 0, 0, 0), null, 16, 6, false); AddImageToImage(g, ResizeImage(qrCodeImage, qrCodeImage.Width - 12, qrCodeImage.Height), new Point(735, 377)); var FinalImage = byteToImage(Bitmap2Byte(bitmap)); //"售" //bitmap.Save(TrainTicket.savePath + tickInfo.GetHashCode() + ".jpg", ImageFormat.Jpeg); //TrainTicket.TrainTicketImages.Add(byteToImage(Bitmap2Byte(bitmap))); g.Dispose(); bitmap.Dispose(); //image.Dispose(); return(FinalImage); }