LabelingPosition.cs 2.1 KB
using Model;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DeviceLibrary.AutoScanAndLabel
{
    public static class LabelingPosition
    {
        /// <summary>
        /// 顺时针旋转
        /// </summary>
        /// <param name="lable">标签坐标</param>
        /// <param name="center">中心点</param>
        /// <param name="angle">旋转角度</param>
        /// <returns></returns>
        public static Point ClockwiseRotation(Point lable, Point center, double angle)
        {           
            angle += 83;
            double theta = angle * Math.PI / 180;
            double x_new = (lable.X - center.X) * Math.Cos(theta) - (lable.Y - center.Y) * Math.Sin(theta) + center.X;
            double y_new = (lable.X - center.X) * Math.Sin(theta) + (lable.Y - center.Y) * Math.Cos(theta) + center.Y;
            LogNet.log.Info($"原坐标:{lable},中心点:{center},顺时针旋转:{angle}度,新坐标:x={x_new},y={y_new};");
            return new Point((int)x_new, (int)y_new);
        }


        static void ImageSave(Bitmap bitmap)
        {
            string filepath = Application.StartupPath + "\\image\\Labeling\\";
            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }
            else if (Directory.GetFiles(filepath).Length > 100)
            {
                try
                {
                    Directory.Delete(filepath, true);
                    Directory.CreateDirectory(filepath);
                }
                catch (Exception)
                {
                    LogNet.log.Info($"删除失败:{filepath}");
                }
            }

            Bitmap bitmaps = (Bitmap)bitmap.Clone();
            bitmaps.Save(filepath + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + DateTime.Now.Millisecond + ".jpg");
            //LabelResult?.Invoke(new LabelResult() { Bitmap = (Bitmap)bitmap.Clone() });
            //bitmap.Dispose();
        }
    }
}