Beispiel #1
0
        public static bool WritePixelImageAsPng(Stream s, IPixelImage img, Action <int> reportProgress, Func <bool> shouldCancel)
        {
            var imgInfo = new ImageInfo(img.Width, img.Height, 8, true);

            var writer = new PngWriter(s, imgInfo);

            for (var y = 0; y < img.Height; y++)
            {
                if (shouldCancel())
                {
                    return(false);
                }

                var line = new ImageLine(imgInfo);
                for (var x = 0; x < img.Width; x++)
                {
                    var c      = img.GetPixel(x, y);
                    var offset = x * 4;
                    line.Scanline[offset]     = c.R;
                    line.Scanline[offset + 1] = c.G;
                    line.Scanline[offset + 2] = c.B;
                    line.Scanline[offset + 3] = c.A;
                }

                writer.WriteRow(line, y);

                reportProgress((y * 100) / img.Height);
            }

            writer.End();

            return(true);
        }
Beispiel #2
0
        public static Bitmap ToBitmap(IPixelImage map)
        {
            var b = new Bitmap(map.Width, map.Height);

            for (var y = 0; y < map.Height; y++)
            {
                for (var x = 0; x < map.Width; x++)
                {
                    b.SetPixel(x, y, map.GetPixel(x, y));
                }
            }

            return(b);
        }