예제 #1
0
파일: Core.cs 프로젝트: manhg/malyst
        /// <summary>
        /// Constuctor with import
        /// </summary>
        /// <param name="fileName">Tệp nguồn ảnh</param>
        /// <param name="handler">Handler của đối tượng tạo ra đối tượng này
        /// Sử dụng để gắn handler của đối tượng gốc cho nó</param>
        public Acquired(Bitmap bmp, CoreMsgEventHandler handler)
        {
            this.CoreMsg         += handler;
            this.ImagePixelFormat = bmp.PixelFormat;
            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

            System.Drawing.Imaging.BitmapData bmpData =
                bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
                             bmp.PixelFormat);
            // Get the address of the first line.
            IntPtr ptr = bmpData.Scan0;

            // Declare an array to hold the bytes of the bitmap.
            this.Stride        = bmpData.Stride;
            this.BytesPerPixel = bmpData.Stride / bmpData.Width;
            this.Height        = bmp.Height;
            this.Width         = bmp.Width;
            int bytes = bmpData.Stride * bmp.Height;

            this.pixel = new byte[bytes];
            // Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, pixel, 0, bytes);
            bmp.UnlockBits(bmpData);
            Inform(this, "Đọc xong {0}.", this.FileName);
        }
예제 #2
0
파일: Core.cs 프로젝트: manhg/malyst
 public Prepare(string fileName, CoreMsgEventHandler handler)
 {
     this.CoreMsg      += handler;
     bmp                = null;
     IsForFormInterpret = true;
     // Inform(this, "Reading file {0}", fileName);
     Inform(this, "Đang đọc tệp: " + fileName);
     try
     {
         FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
         bmp = new Bitmap(stream);
         if (bmp.VerticalResolution == bmp.HorizontalResolution)
         {
             this.Dpi = bmp.HorizontalResolution;
         }
         else
         {
             Inform(this, "Độ phân giải ngang và dọc khác nhau, quá trình chuẩn bị dừng."); return;
         }
         this.Height = bmp.Height;
         this.Width  = bmp.Width;
         stream.Close();
         this.fileName = fileName;
     }
     catch (IOException ex) { Inform(this, "Có vấn đề khi đọc tệp: {0}. Quá trình dừng.", ex.Message); }
     catch (Exception) { };
 }
예제 #3
0
파일: Core.cs 프로젝트: manhg/malyst
 public Interpret(KeySuite keys, Acquired acquired, Anchor anchor, CoreMsgEventHandler handler)
 {
     this.result      = new Discover();
     this.result.file = acquired.FileName;
     this.CoreMsg    += handler;
     this.acq         = acquired;
     this.keys        = keys;
     place            = new Place(anchor, this.CoreMsgDelegates);
 }
예제 #4
0
파일: Core.cs 프로젝트: manhg/malyst
 public Place(Anchor anchor, CoreMsgEventHandler handler)
 {
     this.CoreMsg += handler;
     root          = anchor[AnchorType.TopLeft];
     angle         = Math.Atan2(
         anchor[AnchorType.TopLeft].X - anchor[AnchorType.BottomLeft].X,
         anchor[AnchorType.BottomLeft].Y - anchor[AnchorType.TopLeft].Y);
     // Tỉ lệ = Khoảng cách thực TL-BL với chiều dài lý thuyết.
     scale = Spot.Distance(anchor[AnchorType.TopLeft], anchor[AnchorType.BottomLeft])
             / (UI.Properties.Settings.Default.dHorizonalAnchorDistanceByBase * d);
     root = R2A(d * UI.Properties.Settings.Default.dRootOffsetByX,
                d * UI.Properties.Settings.Default.dRootOffsetByY);
 }
예제 #5
0
파일: Core.cs 프로젝트: manhg/malyst
 public Anchor(Acquired acq, CoreMsgEventHandler handler)
 {
     this.CoreMsg       += handler;
     this.acq            = acq;
     SearchAnchorBoxSize = acq.Width / 4;
 }