/// <summary>
        /// OverlaySaveBtnClick 호출 시 실행되는 내용
        /// </summary>
        private void OnOverlaySave()
        {
            var dialog = new SaveFileDialog
            {
                Filter = "Bitmap Files (*.bmp)|*.bmp"
            };

            if ((bool)dialog.ShowDialog())
            {
                //오버레이 이미지 100% 사이즈 크기를 Bitmap 파일로 변경
                var bmp = m_Display.CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Image).Clone() as System.Drawing.Bitmap;
                //파일 저장
                bmp.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
            }
        }
Example #2
0
        public static void SaveImage(CogRecordDisplay crd, bool b)
        {
            if (b)
            {
                var ymd   = DateTime.Now.ToString("yyyy-MM-dd");
                var mtime = DateTime.Now.ToString("hh点mm分ss秒");
                var path1 = datapath + @"Image\" + ymd;


                var crt = new CogRectangle();

                if (File.Exists(path1))
                {
                    crd.CreateContentBitmap(CogDisplayContentBitmapConstants.Image, crt, 0)
                    .Save(path1 + @"\" + mtime + ".jpg");
                }
                else
                {
                    Directory.CreateDirectory(path1);
                    crd.CreateContentBitmap(CogDisplayContentBitmapConstants.Image, crt, 0)
                    .Save(path1 + @"\" + mtime + ".jpg");
                }
            }
        }
Example #3
0
        //保存图像,自定义文件名
        private void SaveImg(CogRecordDisplay cogRecordDisplay, string path)
        {
            if (cogRecordDisplay.Image == null)   //判断是否有图片
            {
                return;
            }
            if (!Directory.Exists(Application.StartupPath + path))    //如果没有同名文件夹,就创建一个文件夹
            {
                Directory.CreateDirectory(Application.StartupPath + path);
            }
            //保存图片至文件(24位位图)
            Image image = default(Image);

            image = cogRecordDisplay.CreateContentBitmap(Cognex.VisionPro.Display.CogDisplayContentBitmapConstants.Image, null, 0);
            image.Save(Application.StartupPath + path + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".png", ImageFormat.Bmp);  //路径、时间、格式
        }
        private void LogToDisk_ExceptionEaten()
        {
            try
            {
                using (var fileTool = new CogImageFileTool())
                {
                    var img = _display.CreateContentBitmap(_bitmapStyle);

                    var bmp      = new Bitmap(img);
                    var cogImage = new CogImage24PlanarColor(bmp);
                    fileTool.InputImage = cogImage;

                    fileTool.Operator.Open(_recentImagePath, CogImageFileModeConstants.Write);
                    fileTool.Run();
                }
            }

            catch
            {
            }
        }
Example #5
0
        public static void saveImage(CogRecordDisplay image, int index, string result)
        {
            var imageBaseDir = AppDomain.CurrentDomain.BaseDirectory + "Image";

            if (!Directory.Exists(imageBaseDir))
            {
                Directory.CreateDirectory(imageBaseDir);
            }


            var imageDir_today = imageBaseDir + "\\" + DateTime.Now.ToString("MM-dd");

            if (!Directory.Exists(imageDir_today))
            {
                Directory.CreateDirectory(imageDir_today);
            }

            var imagePath = imageDir_today + "\\" + index + "_" + DateTime.Now.ToString("HHmmss") + ".jpg";

            if (result == resultNG)
            {
                lock (mu_recentNGImagePath)
                {
                    recentNGIMagePath = imagePath;
                }
            }

            if (ShouldImageBeSavedBasedOnResult(result))
            {
                try
                {
                    using (var fileTool = new CogImageFileTool())
                    {
                        Image img;
                        lock (mu_SaveAsScreenShot)
                        {
                            img = image.CreateContentBitmap(saveAsScreenShot
                                ? CogDisplayContentBitmapConstants.Display
                                : CogDisplayContentBitmapConstants.Image);
                        }

                        var bmp      = new Bitmap(img);
                        var cogImage = new CogImage24PlanarColor(bmp);
                        fileTool.InputImage = cogImage;
                        lock (mu_recentNGImagePath)
                        {
                            fileTool.Operator.Open(imagePath, CogImageFileModeConstants.Write);
                        }

                        fileTool.Run();
                    }
                }
                catch
                {
                }
            }


            //删除过期文件夹
            removeOutdatedDirs(imageBaseDir);
        }