2

我尝试通过 GDI 创建填充和橡皮擦工具,但这种方式对于 Windows 手机设备来说太慢了,并且使用这种方法处理大照片对于这些设备来说太难了。我搜索替代解决方案并Image Processing找到但不确定这些 Api 是否可以帮助我创建这些工具。Win2DSharpdx

这是填写工具winrtxamltoolkit

 public static void FloodFill(this WriteableBitmap target, int x, int y, int outlineColor, int fillColor, byte maxdiff)
    {
        var width = target.PixelWidth;
        var height = target.PixelHeight;
        var queue = new List<Pnt>();

        using (var context = target.GetBitmapContext(ReadWriteMode.ReadWrite))
        {

            queue.Add(new Pnt { X = x, Y = y });

            while (queue.Count > 0)
            {
                var p = queue[queue.Count - 1];
                queue.RemoveAt(queue.Count - 1);
                if (p.X == -1) continue;
                if (p.X == width) continue;
                if (p.Y == -1) continue;
                if (p.Y == height) continue;
                if (context.Pixels[width * p.Y + p.X] == outlineColor) continue;
                if (context.Pixels[width * p.Y + p.X] == fillColor) continue;
                if (context.Pixels[width * p.Y + p.X].MaxDiff(outlineColor) > maxdiff)
                {
                    context.Pixels[width * p.Y + p.X] = fillColor;
                }
                else
                {
                    continue;
                }
                context.Pixels[width * p.Y + p.X] = fillColor;
                queue.Add(new Pnt { X = p.X, Y = p.Y - 1 });
                queue.Add(new Pnt { X = p.X + 1, Y = p.Y });
                queue.Add(new Pnt { X = p.X, Y = p.Y + 1 });
                queue.Add(new Pnt { X = p.X - 1, Y = p.Y });
            }

            target.Invalidate();

        }
    }

这是Ereaser工具WriteableBitmapEx

public static void FillEllipseCenteredTrsnceparent(this WriteableBitmap bmp, int xc, int yc, int xr, int yr, Color color)
    {
        using (BitmapContext context = bmp.GetBitmapContext())
        {
            Func<Color, int> toInt32 = c =>
            {
                var i = ((((c.A << 0x18) | (((c.R * c.A + 1) >> 8) << 0x10)) | (((c.G * c.A + 1) >> 8) << 8)) | ((c.B * c.A + 1) >> 8));
                return i;
            };
            int[] pixels = context.Pixels;
            int width = context.Width;
            int height = context.Height;
            if ((xr >= 1) && (yr >= 1))
            {
                int num3;
                int num4;
                int num5;
                int num6;
                int num7;
                int num8;
                int num9 = xr;
                int num10 = 0;
                int num11 = (xr * xr) << 1;
                int num12 = (yr * yr) << 1;
                int num13 = (yr * yr) * (1 - (xr << 1));
                int num14 = xr * xr;
                int num15 = 0;
                int num16 = num12 * xr;
                int num17 = 0;
                //int sa = (color >> 0x18) & 0xff;
                //int sr = (color >> 0x10) & 0xff;
                //int sg = (color >> 8) & 0xff;
                //int sb = color & 0xff;
                //bool flag = !doAlphaBlend || (sa == 0xff);
                while (num16 >= num17)
                {
                    num5 = yc + num10;
                    num6 = yc - num10;
                    if (num5 < 0)
                    {
                        num5 = 0;
                    }
                    if (num5 >= height)
                    {
                        num5 = height - 1;
                    }
                    if (num6 < 0)
                    {
                        num6 = 0;
                    }
                    if (num6 >= height)
                    {
                        num6 = height - 1;
                    }
                    num3 = num5 * width;
                    num4 = num6 * width;
                    num8 = xc + num9;
                    num7 = xc - num9;
                    if (num8 < 0)
                    {
                        num8 = 0;
                    }
                    if (num8 >= width)
                    {
                        num8 = width - 1;
                    }
                    if (num7 < 0)
                    {
                        num7 = 0;
                    }
                    if (num7 >= width)
                    {
                        num7 = width - 1;
                    }
                    for (int i = num7; i <= num8; i++)
                    {
                        pixels[i + num3] = toInt32(color);
                        pixels[i + num4] = toInt32(color);
                    }
                    num10++;
                    num17 += num11;
                    num15 += num14;
                    num14 += num11;
                    if ((num13 + (num15 << 1)) > 0)
                    {
                        num9--;
                        num16 -= num12;
                        num15 += num13;
                        num13 += num12;
                    }
                }
                num9 = 0;
                num10 = yr;
                num5 = yc + num10;
                num6 = yc - num10;
                if (num5 < 0)
                {
                    num5 = 0;
                }
                if (num5 >= height)
                {
                    num5 = height - 1;
                }
                if (num6 < 0)
                {
                    num6 = 0;
                }
                if (num6 >= height)
                {
                    num6 = height - 1;
                }
                num3 = num5 * width;
                num4 = num6 * width;
                num13 = yr * yr;
                num14 = (xr * xr) * (1 - (yr << 1));
                num15 = 0;
                num16 = 0;
                num17 = num11 * yr;
                while (num16 <= num17)
                {
                    num8 = xc + num9;
                    num7 = xc - num9;
                    if (num8 < 0)
                    {
                        num8 = 0;
                    }
                    if (num8 >= width)
                    {
                        num8 = width - 1;
                    }
                    if (num7 < 0)
                    {
                        num7 = 0;
                    }
                    if (num7 >= width)
                    {
                        num7 = width - 1;
                    }
                    for (int j = num7; j <= num8; j++)
                    {
                        pixels[j + num3] = toInt32(color);
                        pixels[j + num4] = toInt32(color);
                    }
                    num9++;
                    num16 += num12;
                    num15 += num13;
                    num13 += num12;
                    if ((num14 + (num15 << 1)) > 0)
                    {
                        num10--;
                        num5 = yc + num10;
                        num6 = yc - num10;
                        if (num5 < 0)
                        {
                            num5 = 0;
                        }
                        if (num5 >= height)
                        {
                            num5 = height - 1;
                        }
                        if (num6 < 0)
                        {
                            num6 = 0;
                        }
                        if (num6 >= height)
                        {
                            num6 = height - 1;
                        }
                        num3 = num5 * width;
                        num4 = num6 * width;
                        num17 -= num11;
                        num15 += num14;
                        num14 += num11;
                    }
                }
            }
        }
    }

有没有办法将此代码转换为win2dor Sharpdx

4

0 回答 0