GetPixel() public méthode

public GetPixel ( int x, int y ) : ConsolePixel
x int
y int
Résultat ConsolePixel
        private ConsoleBitmapRawFrame GetRawFrame(ConsoleBitmap bitmap)
        {
            var rawFrame = new ConsoleBitmapRawFrame();

            rawFrame.Pixels = new ConsoleCharacter[bitmap.Width][];
            for (int x = 0; x < bitmap.Width; x++)
            {
                rawFrame.Pixels[x] = new ConsoleCharacter[bitmap.Height];
                for (int y = 0; y < bitmap.Height; y++)
                {
                    var pixelValue = bitmap.GetPixel(x, y).Value.HasValue ? bitmap.GetPixel(x, y).Value.Value : new ConsoleCharacter(' ');
                    rawFrame.Pixels[x][y] = pixelValue;
                }
            }
            return(rawFrame);
        }
        private ConsoleBitmapDiffFrame PrepareDiffFrame(ConsoleBitmap bitmap)
        {
            ConsoleBitmapDiffFrame diff = new ConsoleBitmapDiffFrame();

            diff.Diffs = new List <ConsoleBitmapPixelDiff>();
            int changes = 0;

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    var pixel = bitmap.GetPixel(x, y);
                    if (pixel.HasChanged)
                    {
                        changes++;
                        if (pixel.Value.HasValue)
                        {
                            diff.Diffs.Add(new ConsoleBitmapPixelDiff()
                            {
                                X     = x,
                                Y     = y,
                                Value = pixel.Value.Value
                            });
                        }
                    }
                }
            }

            return(diff);
        }
Exemple #3
0
        private ConsoleBitmapDiffFrame PrepareDiffFrame(ConsoleBitmapRawFrame previous, ConsoleBitmap bitmap)
        {
            ConsoleBitmapDiffFrame diff = new ConsoleBitmapDiffFrame();

            diff.Diffs = new List <ConsoleBitmapPixelDiff>();
            int changes = 0;

            for (int y = 0; y < GetEffectiveHeight(bitmap); y++)
            {
                for (int x = 0; x < GetEffectiveWidth(bitmap); x++)
                {
                    var pixel            = bitmap.GetPixel(GetEffectiveLeft + x, GetEffectiveTop + y);
                    var hasPreviousPixel = previous.Pixels.Length == GetEffectiveWidth(bitmap) && previous.Pixels[0].Length == GetEffectiveHeight(bitmap);
                    var previousPixel    = hasPreviousPixel ? previous.Pixels[x][y] : default(ConsoleCharacter);

                    if (pixel.HasChanged || hasPreviousPixel == false || (pixel.Value.HasValue && pixel.Value.Value.Equals(previousPixel) == false))
                    {
                        changes++;
                        if (pixel.Value.HasValue)
                        {
                            diff.Diffs.Add(new ConsoleBitmapPixelDiff()
                            {
                                X     = x,
                                Y     = y,
                                Value = pixel.Value.Value
                            });
                        }
                    }
                }
            }

            return(diff);
        }
Exemple #4
0
        private ConsoleBitmapRawFrame GetRawFrame(ConsoleBitmap bitmap)
        {
            var rawFrame = new ConsoleBitmapRawFrame();

            rawFrame.Pixels = new ConsoleCharacter[GetEffectiveWidth(bitmap)][];
            for (int x = 0; x < GetEffectiveWidth(bitmap); x++)
            {
                rawFrame.Pixels[x] = new ConsoleCharacter[GetEffectiveHeight(bitmap)];
                for (int y = 0; y < GetEffectiveHeight(bitmap); y++)
                {
                    var pixel      = bitmap.GetPixel(GetEffectiveLeft + x, GetEffectiveTop + y);
                    var pixelValue = pixel.Value.HasValue ? pixel.Value.Value : defaultChar;
                    rawFrame.Pixels[x][y] = pixelValue;
                }
            }
            return(rawFrame);
        }
Exemple #5
0
        /// <summary>
        /// Serializes the given bitmap into a string that will visually look like the given bitmap, with color information
        /// included in the output
        /// </summary>
        /// <param name="bmp">the image to serialize</param>
        /// <returns>the serialized image as a string</returns>
        public static string Serialize(ConsoleBitmap bmp)
        {
            var pallate = ColorPallate.FromBitmap(bmp);
            var ret     = "";

            // horizontal line of hashes
            var bar = "";

            for (var x = 0; x < bmp.Width + 2; x++)
            {
                bar += "#";
            }

            ret += $"{bar}\n";

            for (var y = 0; y < bmp.Height; y++)
            {
                var visuals = "#";
                var colors  = "#    ";
                for (var x = 0; x < bmp.Width; x++)
                {
                    var pix = bmp.GetPixel(x, y);
                    var fg  = pix.ForegroundColor;
                    var bg  = pix.BackgroundColor;
                    var val = pix.Value;

                    visuals += val;
                    colors  += pallate.LookupFormatted(fg, bg);
                    if (x < bmp.Width - 1)
                    {
                        colors += "  ";
                    }
                }
                ret += visuals + colors + "\n";
            }

            // horizontal line of hashes
            ret += $"{bar}\n";
            ret += pallate.Serialize();
            return(ret);
        }
Exemple #6
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            var           fullSize          = ScrollableContentSize;
            ConsoleBitmap fullyPaintedPanel = new ConsoleBitmap(0, 0, fullSize.Width, fullSize.Height);

            ScrollableContent.PaintTo(fullyPaintedPanel);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int scrollX = x + HorizontalScrollUnits;
                    int scrollY = y + VerticalScrollUnits;

                    if (scrollX >= fullyPaintedPanel.Width || scrollY >= fullyPaintedPanel.Height)
                    {
                        continue;
                    }

                    var scrolledPixel = fullyPaintedPanel.GetPixel(scrollX, scrollY);

                    if (scrolledPixel.Value.HasValue)
                    {
                        context.Pen = scrolledPixel.Value.Value;
                    }
                    else
                    {
                        context.Pen = new ConsoleCharacter(' ', backgroundColor: Background);
                    }

                    context.DrawPoint(x, y);
                }
            }

            base.OnPaint(context);
        }
        protected override void OnPaint(ConsoleBitmap context)
        {
            var fullSize = ScrollableContentSize;
            ConsoleBitmap fullyPaintedPanel = new ConsoleBitmap(0, 0, fullSize.Width, fullSize.Height);
            ScrollableContent.PaintTo(fullyPaintedPanel);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int scrollX = x + HorizontalScrollUnits;
                    int scrollY = y + VerticalScrollUnits;

                    if (scrollX >= fullyPaintedPanel.Width || scrollY >= fullyPaintedPanel.Height)
                    {
                        continue;
                    }

                    var scrolledPixel = fullyPaintedPanel.GetPixel(scrollX, scrollY);

                    if (scrolledPixel.Value.HasValue)
                    {
                        context.Pen = scrolledPixel.Value.Value;
                    }
                    else
                    {
                        context.Pen = new ConsoleCharacter(' ', backgroundColor: Background);
                    }

                    context.DrawPoint(x, y);
                }
            }

            base.OnPaint(context);
        }