几何尺寸与公差论坛

 找回密码
 注册
查看: 367|回复: 1

如何对图像进行像素编辑?

[复制链接]
发表于 2023-1-28 10:14:58 | 显示全部楼层 |阅读模式
private static void CopyImagePixels(ICogImage src, Cognex.VisionPro.ICogRegion srcRegion, ICogImage dest, double destAlignmentX, double destAlignmentY)
        {
            if(null == src)
            {
                return;
            }
            CogImage16Range test = src as CogImage16Range;
            CogImage16Range destNew = dest as CogImage16Range;
            CogRectangle rectangle = srcRegion as CogRectangle;
            if (false == destNew.Allocated)
            {
                destNew.Allocate((int)(rectangle.Width), (int)(rectangle.Height));
            }

            //test.GetPixel(0, 0, out bool VisibleValue, out ushort PixelValue);
            for(double row = rectangle.X; row < rectangle.X + rectangle.Width; row += 100)
            {
                for (double col = rectangle.Y; col < rectangle.Y + rectangle.Height; col += 100)
                {
                    int newRow = (int)(row - rectangle.X);
                    int newCol = (int)(col - rectangle.Y);
                    test.GetPixel((int)row, (int)col, out bool VisibleValue, out ushort PixelValue);
                    destNew.SetPixel(newRow, newCol, VisibleValue, 2550);
                }
            }
            dest = destNew;
        }
 楼主| 发表于 2023-1-28 10:15:57 | 显示全部楼层
                CogMaskGraphic cogMask = new CogMaskGraphic();
                CogImage16Range dest = new CogImage16Range();
                CopyImagePixels(sourceImage, region, dest, 0, 0);
                cogMask.Image = new CogImage8Grey(dest.ToBitmap());
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-3-29 14:49 , Processed in 0.036058 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表