Esempio n. 1
0
        private byte[] GetBarcodeBytes(string text, BarcodeFormat format)
        {
            var       qrCodeWriter = new QRCodeWriter();
            BitMatrix bm           = qrCodeWriter.encode(text, format, 600, 600);
            int       squareLength = bm.Width;

            //HACK: we are manually creating each pixel? there must be an easier way
            SKBitmap bitmap = new SKBitmap(squareLength, squareLength);

            for (int row = 0; row < squareLength; row++)
            {
                for (int col = 0; col < squareLength; col++)
                {
                    if (bm[row, col])
                    {
                        bitmap.SetPixel(row, col, SKColors.Black);
                    }
                    else
                    {
                        bitmap.SetPixel(row, col, SKColors.White);
                    }
                }
            }

            SKData data = SKImage.FromBitmap(bitmap).Encode();

            return(data.ToArray());
        }
Esempio n. 2
0
        private async Task CreateWithPickedBitmap()
        {
            if (_applyDitherBitmap == null)
            {
                return;
            }

            for (int x = 0; x < _applyDitherBitmap.Width; x++)
            {
                for (int y = 0; y < _applyDitherBitmap.Height; y++)
                {
                    var pixel = _applyDitherBitmap.GetPixel(x, y);

                    var color1     = _selectedColorPalette.Colors.OrderBy(colorFromPalette => ColorDistance(pixel, colorFromPalette)).FirstOrDefault();
                    var colorDist1 = ColorDistance(pixel, color1);
                    var color2     = _selectedColorPalette.Colors.OrderBy(colorFromPalette => ColorDistance(pixel, colorFromPalette)).ElementAt(1);
                    var colorDist2 = ColorDistance(pixel, color2);

                    var ditherFactor = DitherSlider.Value * 50;

                    if (Math.Abs(colorDist1 - colorDist2) > ditherFactor || (x % 2 == y % 2))
                    {
                        _applyDitherBitmap.SetPixel(x, y, color1);
                    }
                    else
                    {
                        _applyDitherBitmap.SetPixel(x, y, color2);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Separate Image into Black and Red Image
        /// </summary>
        /// <param name="image"></param>
        /// <param name="imageBw"></param>
        /// <param name="imageRed"></param>
        private static void SeparateColors(SKBitmap image, out SKBitmap imageBw, out SKBitmap imageRed)
        {
            int width  = image.Width;
            int height = image.Height;

            imageBw  = new SKBitmap(width, height);
            imageRed = new SKBitmap(width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var pixel = image.GetPixel(x, y);

                    if (IsRed(pixel.Red, pixel.Green, pixel.Blue))
                    {
                        imageRed.SetPixel(x, y, SKColors.Red);
                        imageBw.SetPixel(x, y, SKColors.Black);
                    }
                    else
                    {
                        imageBw.SetPixel(x, y, pixel);
                        imageRed.SetPixel(x, y, SKColors.Black);
                    }
                }
            }
        }
Esempio n. 4
0
        public static SKBitmap CheckeredPattern(SKColor color)
        {
            SKBitmap tmp = new SKBitmap(2, 2);

            tmp = Clear(tmp);
            tmp.SetPixel(1, 0, color);
            tmp.SetPixel(0, 1, color);
            return(tmp);
        }
Esempio n. 5
0
        private void InvertDraw(SKBitmap skBitmap, SKBitmap skBitmapInvert)
        {
            // Fast local copy
            var originalBytes = skBitmap.GetPixelSpan();
            var invertBytes   = skBitmapInvert.GetPixelSpan();

            int total = originalBytes.Length / 4;

            for (int i = 0; i < total; i++)
            {
                // RGBA8888
                int alphaByte = (i << 2) + 3;
                if (invertBytes[alphaByte] == 0)
                {
                    continue;
                }

                // Set color
                var targetColor = SKColors.White;
                if (originalBytes[alphaByte - 1] == 255)
                {
                    targetColor = SKColors.Black;
                }

                int x, y;
                y = Math.DivRem(i, skBitmapInvert.Width, out x);

                skBitmap.SetPixel(x, y, targetColor);
            }
        }
Esempio n. 6
0
            private SKBitmap ReadRegion(SizeL location, int level, SizeL size)
            {
                Stopwatch sw = new Stopwatch();

                sw.Start();
                OpenSlide.TraceMsg("start ReadRegion " + level + "/" + location.Height + "_" + location.Width + ": " + GetBytesReadable(size.Width * size.Height * 3));
                SKBitmap bmp = new SKBitmap((int)size.Width, (int)size.Height);

                bmp.SetPixel(0, 0, SKColors.AliceBlue);
                bmp.LockPixels();
                var bmpdata = bmp.GetPixels();

                OpenSlide.TraceMsg("bmp locked " + level + "/" + location.Height + "_" + location.Width);
                unsafe
                {
                    void *p = bmpdata.ToPointer();
                    Import.openslide_read_region(handle, p, location.Width, location.Height, level, size.Width, size.Height);
                }
                OpenSlide.TraceMsg("read finished " + level + "/" + location.Height + "_" + location.Width + ": " + GetBytesReadable(size.Width * size.Height * 3 / Math.Max(sw.ElapsedMilliseconds, 1)) + "/ms");
                bmp.UnlockPixels();
                OpenSlide.TraceMsg("unlock bits " + level + "/" + location.Height + "_" + location.Width);
                if (bmp.GetPixel(0, 0) == SKColors.Black)
                {
                    var error = CheckForLastError();
                    if (error != null)
                    {
                        throw new ArgumentException($"error reading region loc:{location}, level:{level}, size:{size}" + error);
                    }
                    //else just a black image?
                }
                OpenSlide.TraceMsg("end ReadRegion " + level + "/" + location.Height + "_" + location.Width);
                return(bmp);
            }
Esempio n. 7
0
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplDataMatrix dataMatrix)
            {
                float x = dataMatrix.PositionX;
                float y = dataMatrix.PositionY;

                if (dataMatrix.FieldTypeset != null)
                {
                    y -= dataMatrix.Height;
                }

                var writer = new DataMatrixWriter();
                var result = writer.encode(dataMatrix.Content, BarcodeFormat.DATA_MATRIX, 0, 0);

                int size = dataMatrix.Height;
                using var image = new SKBitmap(result.Width + size - 1, result.Height + size - 1);

                for (int row = 0; row < result.Height; row++)
                {
                    for (int col = 0; col < result.Width; col++)
                    {
                        var color = result[row, col] ? SKColors.Black : SKColors.White;
                        image.SetPixel(row, col, color);
                    }
                }

                using var resizedImage = image.Resize(new SKSizeI(image.Width * size, image.Height * size), SKFilterQuality.None);

                var png = resizedImage.Encode(SKEncodedImageFormat.Png, 100).ToArray();
                this.DrawBarcode(png, dataMatrix.Height, dataMatrix.Height, dataMatrix.FieldOrigin != null, x, y, dataMatrix.FieldOrientation);
            }
        }
        public SKBitmap GetDecorateSelectedBitmap()
        {
            SKBitmap initialImageStretched = new SKBitmap(DecorateSelectionImageBitmap.Width, DecorateSelectionImageBitmap.Height);

            using (SKCanvas canvas = new SKCanvas(initialImageStretched))
            {
                canvas.DrawBitmap(
                    DecorateInitialImageBitmap,
                    new SKRect(0, 0, DecorateSelectionImageBitmap.Width, DecorateSelectionImageBitmap.Height),
                    BitmapStretch.Uniform);
            }

            DecorateInitialImageStretchedBitmap = initialImageStretched;

            SKBitmap selectedBitmap = new SKBitmap(DecorateSelectionImageBitmap.Width, DecorateSelectionImageBitmap.Height);

            for (int x = 0; x < DecorateSelectionImageBitmap.Width; ++x)
            {
                for (int y = 0; y < DecorateSelectionImageBitmap.Height; ++y)
                {
                    selectedBitmap.SetPixel(x, y,
                                            DecorateSelectionImageBitmap.GetPixel(x, y).Red == 0
                            ? new SKColor(0, 0, 0, 0)
                            : initialImageStretched.GetPixel(x, y));
                }
            }

            return(selectedBitmap);
        }
Esempio n. 9
0
        /// <summary>
        /// Сохранение изображения в файл
        /// </summary>
        /// <param name="path">Путь, по которому изображение будет сохранено. Если папки в этом пути не существуют, они будут созданы</param>
        public void Save(string path)
        {
            if (!CanSaveImage(path))
            {
                throw new ArgumentException("Can not save image using specified image format");
            }
            string directory = Path.GetDirectoryName(path);

            Directory.CreateDirectory(directory);

            using (var outImage = new SKBitmap(this.Width, this.Height, SKColorType.Rgb888x, SKAlphaType.Opaque))
            {
                for (int i = 0; i < this.Height; i++)
                {
                    for (int j = 0; j < this.Width; j++)
                    {
                        SKColor color = new SKColor(Cast(this[i, j, 0]), Cast(this[i, j, 1]), Cast(this[i, j, 2]));
                        outImage.SetPixel(j, i, color);
                    }
                }

                using (SKImage img = SKImage.FromBitmap(outImage))
                    using (var data = img.Encode(GetFormat(path), 100))
                        using (var stream = File.Create(path))
                            data.SaveTo(stream);
            }
        }
Esempio n. 10
0
        private new void DrawBackground(SKCanvas c)
        {
            c.DrawRect(new SKRect(Margin, Margin, Width - Margin, Height - Margin),
                       new SKPaint
            {
                IsAntialias = true, FilterQuality = SKFilterQuality.High,
                Shader      = SKShader.CreateRadialGradient(new SKPoint(Width / 2, Height / 2), Width / 5 * 2,
                                                            new[] { Background[0], Background[1] },
                                                            SKShaderTileMode.Clamp)
            });

            for (var i = 0; i < _backgroundOverlay.Width; i++)
            {
                for (var j = 0; j < _backgroundOverlay.Height; j++)
                {
                    if (_backgroundOverlay.GetPixel(i, j) == SKColors.Black)
                    {
                        _backgroundOverlay.SetPixel(i, j, SKColors.Transparent);
                    }
                }
            }

            c.DrawBitmap(_backgroundOverlay, new SKRect(Margin, Margin, Width - Margin, Height - Margin), new SKPaint
            {
                IsAntialias = true,
                ColorFilter = SKColorFilter.CreateBlendMode(SKColors.Black.WithAlpha(150), SKBlendMode.DstIn),
                ImageFilter = SKImageFilter.CreateDropShadow(2, 2, 4, 4, new SKColor(0, 0, 0))
            });
            c.DrawColor(SKColors.Black.WithAlpha(125), SKBlendMode.DstIn);
        }
Esempio n. 11
0
        static public SKBitmap GenerateClutImage(int level)
        {
            var cube_size  = level * level;
            var image_size = level * level * level;
            //data = p = malloc((sizeof *data) * image_size * image_size * 3);
            var image = new SKBitmap(image_size, image_size);

            int i = 0;

            for (var blue = 0; blue < cube_size; blue++)
            {
                for (var green = 0; green < cube_size; green++)
                {
                    for (var red = 0; red < cube_size; red++)
                    {
                        var R = (byte)(((float)red / (float)(cube_size - 1)) * 255);
                        var G = (byte)(((float)green / (float)(cube_size - 1)) * 255);
                        var B = (byte)(((float)blue / (float)(cube_size - 1)) * 255);

                        // var pos = red + green + blue;

                        var x     = i % image_size;
                        var y     = i / image_size;
                        var color = new SKColor(R, G, B);
                        image.SetPixel(x, y, color);
                        i++;
                    }
                }
            }

            return(image);
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var image5 = new SKBitmap(1280, 720);

            image5.SetPixel(5, 5, SKColors.Red);
            ImageVisualizer.TestShowVisualizer(image5);
        }
Esempio n. 13
0
        public string GetLightnessPixelsAsync(IFormFile file, int lightness)
        {
            SKBitmap bitmap = SKBitmap.Decode(file.OpenReadStream());

            for (int i = 0; i < bitmap.Width; ++i)
            {
                for (int j = 0; j < bitmap.Height; ++j)
                {
                    var rlin = PixelInfo.ConvertToLinear(PixelInfo.ConvertToDecimal(bitmap.GetPixel(i, j).Red));
                    var glin = PixelInfo.ConvertToLinear(PixelInfo.ConvertToDecimal(bitmap.GetPixel(i, j).Green));
                    var blin = PixelInfo.ConvertToLinear(PixelInfo.ConvertToDecimal(bitmap.GetPixel(i, j).Blue));

                    var Y = PixelInfo.CalculateYLuminence(rlin, glin, blin);

                    var lum = PixelInfo.CalculatePerceivedLightness(Y);
                    if (lum > lightness)
                    {
                        bitmap.SetPixel(i, j, new SKColor(103, 235, 52));
                    }
                }
            }

            var image = SKImage.FromBitmap(bitmap);

            var imageStream = image.Encode().AsStream();

            using (MemoryStream ms = new MemoryStream())
            {
                imageStream.CopyTo(ms);

                var bytesArray = ms.ToArray();

                return(Convert.ToBase64String(bytesArray));
            }
        }
Esempio n. 14
0
        public static SKBitmap Rough3x3Pattern(SKColor color)
        {
            SKBitmap tmp = new SKBitmap(3, 3);

            tmp = Clear(tmp);
            tmp.SetPixel(2, 2, color);
            return(tmp);
        }
Esempio n. 15
0
        public static SKBitmap StripeYPattern(SKColor color)
        {
            SKBitmap tmp = new SKBitmap(2, 1);

            tmp = Clear(tmp);
            tmp.SetPixel(0, 0, color);
            return(tmp);
        }
Esempio n. 16
0
        public static SKBitmap NormalPattern(SKColor color)
        {
            SKBitmap tmp = new SKBitmap(1, 1);

            tmp = Clear(tmp);
            tmp.SetPixel(0, 0, color);
            return(tmp);
        }
Esempio n. 17
0
        public static SKBitmap Rough2x2Pattern(SKColor color)
        {
            SKBitmap tmp = new SKBitmap(2, 2);

            tmp = Clear(tmp);
            tmp.SetPixel(1, 1, color);
            return(tmp);
        }
Esempio n. 18
0
        private static void Render(
            int isx, int isy, int iex, int iey,
            double fsx, double fsy, double fex, double fey,
            int iterations,
            SKBitmap image, SKColor[] palette)
        {
            for (var iy = isy; iy <= iey; iy++)
            {
                for (var ix = isx; ix <= iex; ix++)
                {
                    var z = Complex.Zero;
                    var c = Complex.Create(
                        MathEx.Translate(ix, isx, iex, fsx, fex),
                        MathEx.Translate(iy, isy, iey, fsy, fey));

                    var i = 0;

                    while (z.Norm() < ESCAPE && i < iterations)
                    {
                        z = z * z + c;
                        i++;
                    }

                    double f = i;

                    if (i < iterations)
                    {
                        var logzn = Math.Log(z.Norm()) / 2;
                        var nu    = Math.Log(logzn / LOG2) / LOG2;
                        f = i + 1 - nu;
                    }

                    i = (int)Math.Floor(f);

                    if (i >= iterations)
                    {
                        image.SetPixel(ix, iy, SKColor.Empty);
                        continue;
                    }

                    var color = Interpolate(palette, MathEx.Translate(f, 0, iterations - 1, 0, palette.Length - 1));
                    image.SetPixel(ix, iy, color);
                }
            }
        }
        public HatchBrush(HatchStyle hatchStyle, Color foreColor, Color backColor)
        {
            HatchStyle = hatchStyle;
            SKBitmap bitmap = new SKBitmap(new SKImageInfo(2, 2, SKColorType.Bgra8888));

            bitmap.Erase(backColor.ToSKColor());
            bitmap.SetPixel(0, 0, foreColor.ToSKColor());
            bitmap.SetPixel(1, 1, foreColor.ToSKColor());

            // create the bitmap shader
            var shader = SKShader.CreateBitmap(bitmap, SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);

            // add to the paint
            nativeBrush = new SKPaint()
            {
                Shader = shader, Style = SKPaintStyle.Fill
            };
        }
        public void Execute()
        {
            ProcessedImage = new SKBitmap(ProcessingImage.Width, ProcessingImage.Height);

            for (int x = 0; x < ProcessingImage.Width; x++)
            {
                for (int y = 0; y < ProcessingImage.Height; y++)
                {
                    SKColor pixel = ProcessingImage.GetPixel(x, y);

                    if (x == 0 || y == 0 || x == ProcessingImage.Width - 1 || y == ProcessingImage.Height - 1)
                    {
                        ProcessedImage.SetPixel(x, y, pixel);
                    }
                    else
                    {
                        // 3x3 mask
                        List <byte> mask = new List <byte>
                        {
                            ProcessingImage.GetPixel(x - 1, y - 1).Red,
                            ProcessingImage.GetPixel(x - 1, y).Red,
                            ProcessingImage.GetPixel(x - 1, y + 1).Red,
                            ProcessingImage.GetPixel(x, y - 1).Red,
                            ProcessingImage.GetPixel(x, y).Red,
                            ProcessingImage.GetPixel(x, y + 1).Red,
                            ProcessingImage.GetPixel(x + 1, y - 1).Red,
                            ProcessingImage.GetPixel(x + 1, y).Red,
                            ProcessingImage.GetPixel(x + 1, y + 1).Red
                        };

                        byte average = 0;
                        foreach (byte px in mask)
                        {
                            average += px;
                        }

                        average /= 9;

                        ProcessedImage.SetPixel(x, y, new SKColor(average, average, average, pixel.Alpha));
                    }
                }
            }
        }
        public static void compute_distance_image()
        {
            DMesh3            mesh  = StandardMeshReader.ReadMesh("c:\\scratch\\remesh.obj");
            MeshBoundaryLoops loops = new MeshBoundaryLoops(mesh);
            DCurve3           curve = loops[0].ToCurve();
            Polygon2d         poly  = new Polygon2d();

            foreach (Vector3d v in curve.Vertices)
            {
                poly.AppendVertex(v.xy);
            }
            int      N        = 1024;
            double   cellsize = poly.Bounds.MaxDim / (double)N;
            Vector2d o        = poly.Bounds.Min;

            o -= 4 * cellsize * Vector2d.One;
            N += 8;

            ShiftGridIndexer2 indexer = new ShiftGridIndexer2(poly.Bounds.Min, cellsize);

            double[] df   = new double[N * N];
            double   maxd = 0;

            for (int yi = 0; yi < N; ++yi)
            {
                for (int xi = 0; xi < N; ++xi)
                {
                    Vector2d p = indexer.FromGrid(new Vector2i(xi, yi));
                    double   d = Math.Sqrt(poly.DistanceSquared(p));
                    df[yi * N + xi] = d;
                    maxd            = Math.Max(d, maxd);
                }
            }

            SKBitmap bmp = new SKBitmap(N, N);

            for (int yi = 0; yi < N; ++yi)
            {
                for (int xi = 0; xi < N; ++xi)
                {
                    double d = df[yi * N + xi];
                    float  f = (float)(d / maxd);
                    byte   b = (byte)(int)(f * 255);
                    bmp.SetPixel(xi, yi, new SKColor(b, b, b));
                }
            }

            using (var image = SKImage.FromBitmap(bmp))
                using (var data = image.Encode(SKEncodedImageFormat.Png, 80)) {
                    // save the data to a stream
                    using (var stream = File.OpenWrite("c:\\scratch\\distances.png")) {
                        data.SaveTo(stream);
                    }
                }
        }
Esempio n. 22
0
 /// <summary>
 ///     Takes the input 8bpp bitmap and renders it as a SKBitmap
 ///     using the pre-defined Color Palette
 /// </summary>
 /// <param name="bitmap"></param>
 /// <returns></returns>
 public SKBitmap Render(byte[] bitmap)
 {
     for (var y = 0; y < 240; y++)
     {
         for (var x = 0; x < 256; x++)
         {
             _bitmap.SetPixel(x, y, _colorPalette[bitmap[y * 256 + x]]);
         }
     }
     return(_bitmap);
 }
Esempio n. 23
0
 void imageQuantify(SKBitmap image)
 {
     for (int i = 0; i < image.Width; i++)
     {
         for (int j = 0; j < image.Height; j++)
         {
             var c = image.GetPixel(i, j);
             image.SetPixel(i, j, colorQuantify(c));
             //image.SetPixel(i, j, i % 2 == 0 ? SKColors.Black : SKColors.White);
         }
     }
 }
Esempio n. 24
0
        public string SortPixelsAsync(IFormFile file)
        {
            SKBitmap bitmap = SKBitmap.Decode(file.OpenReadStream());

            var pixels = new List <Pixel>();

            for (int i = 0; i < bitmap.Width; ++i)
            {
                for (int j = 0; j < bitmap.Height; ++j)
                {
                    var rlin = PixelInfo.ConvertToLinear(PixelInfo.ConvertToDecimal(bitmap.GetPixel(i, j).Red));
                    var glin = PixelInfo.ConvertToLinear(PixelInfo.ConvertToDecimal(bitmap.GetPixel(i, j).Green));
                    var blin = PixelInfo.ConvertToLinear(PixelInfo.ConvertToDecimal(bitmap.GetPixel(i, j).Blue));

                    var Y = PixelInfo.CalculateYLuminence(rlin, glin, blin);

                    pixels.Add(new Pixel()
                    {
                        Red       = bitmap.GetPixel(i, j).Red,
                        Green     = bitmap.GetPixel(i, j).Green,
                        Blue      = bitmap.GetPixel(i, j).Blue,
                        Luminence = PixelInfo.CalculatePerceivedLightness(Y)
                    });
                }
            }

            pixels.Sort();

            int k = 0;

            for (int i = 0; i < bitmap.Width; ++i)
            {
                for (int j = 0; j < bitmap.Height; ++j)
                {
                    bitmap.SetPixel(i, j, new SKColor(pixels[k].Red, pixels[k].Green, pixels[k].Blue));

                    k++;
                }
            }

            var image = SKImage.FromBitmap(bitmap);

            var imageStream = image.Encode().AsStream();

            using (MemoryStream ms = new MemoryStream())
            {
                imageStream.CopyTo(ms);

                var bytesArray = ms.ToArray();

                return(Convert.ToBase64String(bytesArray));
            }
        }
Esempio n. 25
0
        public OrderQRCodePageViewModel(Order order)
        {
            OrderID = order.id;
            BitMatrix bmqr = new QRCodeWriter().encode(JsonConvert.SerializeObject(order), ZXing.BarcodeFormat.QR_CODE, 750, 750);

            skbmp = new SKBitmap(bmqr.Width, bmqr.Height);
            for (int i = 0; i < bmqr.Width; i++)
            {
                for (int j = 0; j < bmqr.Height; j++)
                {
                    if (bmqr[i, j])
                    {
                        skbmp.SetPixel(i, j, new SKColor(0, 0, 0));
                    }
                    else
                    {
                        skbmp.SetPixel(i, j, new SKColor(255, 255, 255));
                    }
                }
            }
        }
Esempio n. 26
0
        public bool FillElement(SKSurface surface, SKImageInfo dstinf, SKColor currentColor, int x, int y)
        {
            SKBitmap bitmap = new SKBitmap(dstinf.Width, dstinf.Height);

            IntPtr dstpixels = bitmap.GetPixels();

            surface.ReadPixels(dstinf, dstpixels, dstinf.RowBytes, 0, 0);

            var pointsToFound = new Stack <SKPoint>();

            if (bitmap.GetPixel(x, y) == currentColor)
            {
                return(false);
            }

            pointsToFound.Push(new SKPoint(x, y));

            var baseColor     = bitmap.GetPixel((int)Math.Round(BasePoint.X), (int)Math.Round(BasePoint.Y));
            var currentPoints = new Stack <SKPoint>();

            while (pointsToFound.Count > 0)
            {
                currentPoints.Push(pointsToFound.Pop());
                var currentPoint = currentPoints.Peek();
                var currentX     = (int)currentPoint.X;
                var currentY     = (int)currentPoint.Y;
                bitmap.SetPixel((int)currentPoint.X, (int)currentPoint.Y, currentColor);
                Points.Add(currentPoint);
                //Path.LineTo(currentX, currentY);
                if (currentX - 2 > 0 && currentY - 2 > 0 && currentY + 2 < bitmap.Height && currentX + 2 < bitmap.Width)
                {
                    if (bitmap.GetPixel(currentX, currentY + 2) == baseColor)
                    {
                        pointsToFound.Push(new SKPoint(currentX, currentY + 2));
                    }
                    if (bitmap.GetPixel(currentX, currentY - 2) == baseColor)
                    {
                        pointsToFound.Push(new SKPoint(currentX, currentY - 2));
                    }
                    if (bitmap.GetPixel(currentX + 2, currentY) == baseColor)
                    {
                        pointsToFound.Push(new SKPoint(currentX + 2, currentY));
                    }
                    if (bitmap.GetPixel(currentX - 2, currentY) == baseColor)
                    {
                        pointsToFound.Push(new SKPoint(currentX - 2, currentY));
                    }
                }
            }

            return(true);
        }
Esempio n. 27
0
 private static void ConvertToGrayWithColor(SKBitmap bitmap)
 {
     for (int x = 0; x < bitmap.Width; x++)
     {
         for (int y = 0; y < bitmap.Height; y++)
         {
             var pixel = bitmap.GetPixel(x, y);
             var sum   = pixel.Red + pixel.Green + pixel.Blue;
             var avg   = (byte)(sum / 3);
             bitmap.SetPixel(x, y, new SKColor(avg, avg, avg, pixel.Alpha));
         }
     }
 }
Esempio n. 28
0
        public static SKBitmap Dense3x3Pattern(SKColor color)
        {
            SKBitmap tmp = new SKBitmap(3, 3);

            tmp = Clear(tmp);
            tmp.SetPixel(0, 0, color);
            tmp.SetPixel(1, 0, color);
            tmp.SetPixel(2, 0, color);
            tmp.SetPixel(0, 1, color);
            tmp.SetPixel(1, 1, color);
            tmp.SetPixel(2, 1, color);
            tmp.SetPixel(0, 2, color);
            tmp.SetPixel(1, 2, color);
            return(tmp);
        }
Esempio n. 29
0
        public static SKBitmap RightHatching8x8Pattern(SKColor color)
        {
            SKBitmap tmp = new SKBitmap(8, 8);

            tmp = Clear(tmp);
            tmp.SetPixel(7, 0, color);
            tmp.SetPixel(6, 1, color);
            tmp.SetPixel(5, 2, color);
            tmp.SetPixel(4, 3, color);
            tmp.SetPixel(3, 4, color);
            tmp.SetPixel(2, 5, color);
            tmp.SetPixel(1, 6, color);
            tmp.SetPixel(0, 7, color);
            return(tmp);
        }
Esempio n. 30
0
        public static SKBitmap ReadUIntPixels(BinaryReader r, int w, int h, SKColorType colorType)
        {
            var res = new SKBitmap(w, h, colorType, SKAlphaType.Unpremul);

            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    res.SetPixel(x, y, new SKColor(r.ReadUInt32()));
                }
            }

            return(res);
        }