Esempio n. 1
0
        public static EImageBW8 ImageToEImageBW8(Image image)
        {
            EImageBW8 eImageBW8 = null;

            try
            {
                eImageBW8 = new EImageBW8();
                Bitmap     bitmap  = (Bitmap)image;
                Rectangle  rect    = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadWrite, bitmap.PixelFormat);
                eImageBW8.SetImagePtr(bitmap.Width, bitmap.Height, bmpData.Scan0);
                bitmap.UnlockBits(bmpData);
            }
            catch (EException exc)
            {
                StackFrame[] stackFrames = new StackTrace(true).GetFrames();
                clsLogFile.LogTryCatch(stackFrames, exc.Message, true, true);
            }
            catch (Exception ex)
            {
                StackFrame[] stackFrames = new StackTrace(true).GetFrames();
                clsLogFile.LogTryCatch(stackFrames, ex.Message, true, true);
            }
            return(eImageBW8);
        }
Esempio n. 2
0
        public override bool Run(bool isTaskRun = false)
        {
            OutputImg = new EImageBW8();
            switch (config.SelectMode)
            {
            case 0:
                if (ParentTask.SourceImg != null)
                {
                    OutputImg.SetSize(ParentTask.SourceImg);
                    EasyImage.Copy(ParentTask.SourceImg, OutputImg);
                }
                else
                {
                    OutputImg = null;
                }

                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 1:
                if (!File.Exists(config.ImgPath))
                {
                    return(false);
                }

                OutputImg.Load(config.ImgPath);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 2:
                if (!Directory.Exists(config.FolderPath))
                {
                    return(false);
                }
                DirectoryInfo dir = new DirectoryInfo(config.FolderPath);
                FileInfo[]    fil = dir.GetFiles("*.bmp", SearchOption.TopDirectoryOnly);
                if (fil.Length == 0)
                {
                    return(false);
                }
                if (selectImg >= fil.Length)
                {
                    selectImg = 0;
                }
                OutputImg.Load(fil[selectImg++].FullName);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 3:
                if (config.SelectCCD > 0)
                {
                    int select = config.SelectCCD - 1;
                    if (ParentTask.Cameras[select].IsConnect)
                    {
                        ImgAtt att = ParentTask.Cameras[select].Grab();
                        OutputImg = new EImageBW8();
                        OutputImg.SetImagePtr(att.ImgWidth, att.ImgHeight, att.ImgPointer);

                        if (isTaskRun)
                        {
                            ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                        }
                    }
                    else
                    {
                        OutputImg = null;
                        return(false);
                    }
                }
                else
                {
                    OutputImg = null;
                    return(false);
                }

                break;

            default:
                return(false);
            }
            return(true);
        }