/// private ICogImage GetImage(string imagepath) { if _c# visionpro保存图片">
当前位置:   article > 正文

VisionPro图片的保存,打开,带图形格式的保存_c# visionpro保存图片

c# visionpro保存图片
/// <summary>
        /// 获得ICogImage图像格式
        /// </summary>
        /// <param name="imagepath"></param>
        /// <returns></returns>
        private ICogImage GetImage(string imagepath)
        {
            if (!File.Exists(imagepath))
                return null;
            CogImageFile ImageFile1 = new CogImageFile();
            ICogImage Image;
            ImageFile1.Open(imagepath, CogImageFileModeConstants.Read);
            Image = ImageFile1[0];
            ImageFile1.Close();
            return Image;
        }

        /// <summary>
        /// 原图像保存
        /// </summary>
        /// <param name="display"></param>
        /// <param name="path"></param>
        private void SaveOrignalImage(CogRecordDisplay display, string path)
        {
            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string filename = "_" + DateTime.Now.ToString("HHmmssff") + "_" + ".bmp";

                ICogImage orignalImage = display.Image;
                CogImageFile ImageFile = new CogImageFile();
                ImageFile.Open(path + "\\" + filename, CogImageFileModeConstants.Write);
                ImageFile.Append(orignalImage);
                ImageFile.Close();
            }
            catch (Exception ex)
            {
                Log.WriteTxt("保存图像出现错误:" + ex.Message);

            }

        }

        /// <summary>
        /// 保存图像截图
        /// </summary>
        /// <param name="display"></param>
        /// <param name="path"></param>
        private void SaveScreenImage(CogRecordDisplay display, string path) //保存界面截图jpeg
        {
            try
            {
                //  path = path + "\\" + "Camera-" + index.ToString();
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                string filename = "_" + DateTime.Now.ToString("HHmmssff") + "_" + ".jpg";
                Bitmap bmp = display.CreateContentBitmap(CogDisplayContentBitmapConstants.Image) as Bitmap;
                // Bitmap bmp = display.Image.ToBitmap();
                bmp.Save(path + "\\" + filename, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                Log.WriteTxt("保存处理图像出现错误,信息为" + ex.Message);
            }
        }

        /// <summary>
        /// 将图像转换成CogImage8Grey
        /// </summary>
        /// <param name="imagepath">路径</param>
        /// <returns></returns>
        private CogImage8Grey GetSimulateImage(string imagepath)
        {
            if (File.Exists(imagepath))
                return null;
            CogImageFile ImageFile1 = new CogImageFile();
            CogImage8Grey Image;
            ImageFile1.Open(imagepath, CogImageFileModeConstants.Read);
            Image = (CogImage8Grey)ImageFile1[0];
            ImageFile1.Close();
            return Image;
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/637165
推荐阅读
相关标签
  

闽ICP备14008679号