예제 #1
0
 /// <summary>
 /// 序列化为XML字符串
 /// </summary>
 /// <param name="targetImageConfig"></param>
 /// <returns></returns>
 public static string Serialize(TargetImageConfig targetImageConfig)
 {
     XmlSerializer xs = new XmlSerializer(typeof(TargetImageConfig));
     StringBuilder sbXml = new StringBuilder();
     XmlWriter tw = XmlWriter.Create(sbXml);
     xs.Serialize(tw, targetImageConfig);
     tw.Close();
     return sbXml.ToString();
 }
예제 #2
0
 public SetTargetObjectForm()
 {
     InitializeComponent();
     if (File.Exists(GetConfigPictureFilePath()) && File.Exists(GetConfigSaveFilePath()))
     {
         File.Delete(GetEditConfigPictureFilePath());
         File.Copy(GetConfigPictureFilePath(), GetEditConfigPictureFilePath());
         currentStandardPictureFilePath = GetEditConfigPictureFilePath();
         currentStandardConfig = TargetImageConfig.Deserialize(File.ReadAllText(GetConfigSaveFilePath()));
         Image image = Bitmap.FromFile(currentStandardPictureFilePath);
         bitmap = new Bitmap(image);
         pbStandard.Image = bitmap;
         selectAreaStartPoint = currentStandardConfig.SelectAreaStartPoint;
         selectAreaEndPoint = currentStandardConfig.SelectAreaEndPoint;
         _threshold = currentStandardConfig.Threshold;
         AnalyseSelectArea((ushort)_threshold);
     }
 }
예제 #3
0
        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (selectAreaStartPoint == Point.Empty || selectAreaEndPoint == Point.Empty)
            {
                MessageBox.Show("未框选并确定目标图形范围");
                return;
            }

            // 计算条形码
            int minX = Math.Min(selectAreaStartPoint.X, selectAreaEndPoint.X);
            int maxX = Math.Max(selectAreaStartPoint.X, selectAreaEndPoint.X);
            int minY = Math.Min(selectAreaStartPoint.Y, selectAreaEndPoint.Y);
            int maxY = Math.Max(selectAreaStartPoint.Y, selectAreaEndPoint.Y);
            // 计算框选范围

            // 序列化并保持文件
            TargetImageConfig targetImageConfig = new TargetImageConfig();
            targetImageConfig.Threshold = ushort.Parse(thresholdUpDown.Value.ToString());
            targetImageConfig.SelectAreaStartPoint = selectAreaStartPoint;
            targetImageConfig.SelectAreaEndPoint = selectAreaEndPoint;
            File.WriteAllText(GetConfigSaveFilePath(), TargetImageConfig.Serialize(targetImageConfig));
            this.currentStandardConfig = targetImageConfig;

            // 保存标准图
            File.Delete(GetConfigPictureFilePath());
            File.Copy(currentStandardPictureFilePath, GetConfigPictureFilePath());
            MessageBox.Show("标准图设置成功");
        }