Contact me: hankecnc@gmail.com

导入中缺少反转图像颜色(黑色和白色) #130

推推 grbl 3年前 (2023-01-24) 201次浏览

关闭
sjsivo 打开了这个问题 2017 年 10 月 6 日 · 2 条评论
关闭

导入中缺少反转图像颜色(黑色和白色)#130

sjsivo 打开了这个问题 2017 年 10 月 6 日 · 2 条评论

注释

导入中缺少反转图像颜色(黑色和白色) #130

程序超级好,但缺少一些功能:

  1. 请在图像导入中插入“反转颜色”(现在缺少这种在导入过程中反转黑白图像的可能性),
  2. 仅导入活动区域的优化功能缺少选择功能(在某些情况下仅需要自动选择活动区域而不是整个图像)
  3. mass import more images for engraving(import more images with same parameters for importing)并全部插入到一个nc文件中。- 将来可能用激光打印更多层(具有相同或不同的 z 高度)

感谢您的支持。
最好的问候,
公元前。米兰西瓦克。

导入中缺少反转图像颜色(黑色和白色) #130 arkypita 添加了 增强 标签 2017 年 10 月 8 日
导入中缺少反转图像颜色(黑色和白色) #130
所有者
  1. 容易,好
  2. 你的意思是自动裁剪/修剪白色图像边框?行
  3. 不错,但不是那么容易,也不是 LaserGRBL 的哲学(最小和简单),但永远不要说永远
导入中缺少反转图像颜色(黑色和白色) #130 arkypita 提到了这个问题 2017 年 10 月 17 日
82个任务
导入中缺少反转图像颜色(黑色和白色) #130

你好@arkypita,

我通过将这两个函数添加到 ImageProcessor.cs 并从预览中的按钮调用它来实现自动裁剪。它似乎在白色背景图像中运行良好。

` public void Trim()
{
mOriginal = ImageTrim(mOriginal);
重新计算();
刷新();
}

    private Bitmap ImageTrim(Bitmap bmp)
    {
        int w = bmp.Width;
        int h = bmp.Height;

        Func<int, bool> allWhiteRow = row =>
        {
            for (int i = 0; i < w; ++i)
                if (bmp.GetPixel(i, row).R != 255)
                    return false;
            return true;
        };

        Func<int, bool> allWhiteColumn = col =>
        {
            for (int i = 0; i < h; ++i)
                if (bmp.GetPixel(col, i).R != 255)
                    return false;
            return true;
        };

        int topmost = 0;
        for (int row = 0; row < h; ++row)
        {
            if (allWhiteRow(row))
                topmost = row;
            else break;
        }

        int bottommost = 0;
        for (int row = h - 1; row >= 0; --row)
        {
            if (allWhiteRow(row))
                bottommost = row;
            else break;
        }

        int leftmost = 0, rightmost = 0;
        for (int col = 0; col < w; ++col)
        {
            if (allWhiteColumn(col))
                leftmost = col;
            else
                break;
        }

        for (int col = w - 1; col >= 0; --col)
        {
            if (allWhiteColumn(col))
                rightmost = col;
            else
                break;
        }

        if (rightmost == 0) rightmost = w; // As reached left
        if (bottommost == 0) bottommost = h; // As reached top.

        int croppedWidth = rightmost - leftmost;
        int croppedHeight = bottommost - topmost;

        if (croppedWidth == 0) // No border on left or right
        {
            leftmost = 0;
            croppedWidth = w;
        }

        if (croppedHeight == 0) // No border on top or bottom
        {
            topmost = 0;
            croppedHeight = h;
        }

        try
        {
            var target = new Bitmap(croppedWidth, croppedHeight);
            using (Graphics g = Graphics.FromImage(target))
            {
                g.DrawImage(bmp,
                  new RectangleF(0, 0, croppedWidth, croppedHeight),
                  new RectangleF(leftmost, topmost, croppedWidth, croppedHeight),
                  GraphicsUnit.Pixel);
            }
            return target;
        }
        catch (Exception ex)
        {
            throw new Exception(
              string.Format("Values are topmost={0} btm={1} left={2} right={3} croppedWidth={4} croppedHeight={5}", topmost, bottommost, leftmost, rightmost, croppedWidth, croppedHeight),
              ex);
        }
    }`

我让它在我当地的分支机构工作。

喜欢 (0)