Exemplo n.º 1
0
        private static Cell SetCellColor(Bitmap image, int cellSize, int cellPositionX, int cellPositionY)
        {
            var cellSizeW = image.Width < cellPositionX + cellSize
                ? image.Width - cellPositionX
                : cellSize;
            var cellSizeH = image.Height < cellPositionY + cellSize
                ? image.Height - cellPositionY
                : cellSize;

            var pixels = GetImagePixels(image, cellPositionX, cellPositionY, cellSizeW, cellSizeH);

            var pixelColor = ImageGetter.GetAveragePixel(pixels);

            for (var pixelPositionX = 0; pixelPositionX < cellSizeW; pixelPositionX++)
            {
                for (var pixelPositionY = 0; pixelPositionY < cellSizeH; pixelPositionY++)
                {
                    image.SetPixel(cellPositionX + pixelPositionX, cellPositionY + pixelPositionY, pixelColor);
                }
            }

            return(new Cell
            {
                X = cellPositionX,
                Y = cellPositionY,
                Resolution = new Resolution(cellSizeW, cellSizeH),
                Color = pixelColor
            });
        }
Exemplo n.º 2
0
        private async Task DrawOriginalImageAsync(InputData inputData, CancellationToken ct)
        {
            var sourceImagesTask = LoadSourceImages(inputData.PathToImagesRootFolder, inputData.CellSize, ct);
            var image            = ImageGetter.GetImage(inputData.PathToOriginalImage, inputData);

            DrawImage(inputData, image, image.Width, image.Height);
            var cells      = PixelizeImage(image, inputData, ct);
            var cellImages = await sourceImagesTask;

            logger.Log($"Processing {cellImages.Count} source images");
            BuildMosaic(image, cells, cellImages);
            DrawImage(inputData, image, image.Width, image.Height);
        }
Exemplo n.º 3
0
        private static async Task <List <CellData> > LoadSourceImages(
            string pathToImagesRootFolder,
            int cellSize,
            CancellationToken ct)
        {
            var images = ImageGetter.GetImages(pathToImagesRootFolder, cellSize, ct);

            var cells = images
                        .TakeWhile(image => !ct.IsCancellationRequested)
                        .Select(image => new CellData
            {
                Image = image,
                Color = ImageGetter.GetAveragePixel(GetImagePixels(image, 0, 0, image.Width, image.Height))
            }).ToList();

            FillCellBackground(cells);

            return(cells);
        }