示例#1
0
        public Bitmap ToBitmap(List <int> bits, Bitmap image)
        {
            if (IsImageTooSmall(bits.Count, image))
            {
                throw new ArgumentException("Image is too small!");
            }

            // Bitmap newImage = new Bitmap(image.Width, image.Height);
            Bitmap newImage = new Bitmap(image);

            BitmapUtil.Iterate(image, bits, (point, diff) =>
            {
                NumberColor numberColor = NumberColor.fromColor(image.GetPixel(point.X, point.Y));
                if (numberColor.R <= 253)
                {
                    numberColor.R += diff;
                }
                else if (numberColor.G <= 253)
                {
                    numberColor.G += diff;
                }
                else if (numberColor.B <= 253)
                {
                    numberColor.B += diff;
                }

                newImage.SetPixel(point.X, point.Y, numberColor.toColor());
            });
            return(newImage);
        }
示例#2
0
        public Bitmap ToBitmap(List <int> bits)
        {
            int    size = Convert.ToInt32(Math.Ceiling(Math.Sqrt(bits.Count)));
            Bitmap map  = new Bitmap(size, size);

            BitmapUtil.FillBitmapWithColor(Color.FromArgb(2, 2, 2), map);

            BitmapUtil.Iterate(map, bits,
                               (point, diff) => { map.SetPixel(point.X, point.Y, Color.FromArgb(diff, 0, 0)); });
            return(map);
        }
示例#3
0
        public bool IsImageTooSmall(int diffsCount, Bitmap image)
        {
            int capablePixelsCount = 0;

            BitmapUtil.Iterate(image, point =>
            {
                if (PixelUtil.IsPixelWritable(image.GetPixel(point.X, point.Y)))
                {
                    capablePixelsCount++;
                }
            });
            Console.WriteLine($"Found {capablePixelsCount} writable pixels, {diffsCount} required");
            return(capablePixelsCount < diffsCount);
        }
        public List <int> Parse(Bitmap bitmap)
        {
            List <int> result = new List <int>();

            BitmapUtil.Iterate(bitmap, point =>
            {
                Color color = bitmap.GetPixel(point.X, point.Y);
                int sum     = color.R + color.G + color.B;
                if (sum <= 1)
                {
                    result.Add(sum);
                }
            });
            return(result);
        }
        public List <int> Parse(Bitmap bitmap, Bitmap basemap)
        {
            List <int> result = new List <int>();

            if (bitmap.Width != basemap.Width || bitmap.Height != basemap.Height)
            {
                throw new ArgumentException("Invalid base image!");
            }

            BitmapUtil.Iterate(bitmap, point =>
            {
                NumberColor bitmapColor  = NumberColor.fromColor(bitmap.GetPixel(point.X, point.Y));
                NumberColor basemapColor = NumberColor.fromColor(basemap.GetPixel(point.X, point.Y));
                if (PixelUtil.IsPixelReadable(bitmap.GetPixel(point.X, point.Y)) && PixelUtil.IsPixelReadable(basemap.GetPixel(point.X, point.Y)))
                {
                    int colorDiff = bitmapColor.SubtractNumberColor(basemapColor);
                    result.Add(colorDiff);
                }
            });
            return(result);
        }