public ImageToMozaicConverter(Bitmap bitmap, int tileSize, IEnumerable<PaletteTile> paletteTiles, int desirableWidth, int desirableHeight)
        {
            _image = bitmap;

            _desirableWidth = desirableWidth;

            _desirableHeight = desirableHeight;

            _gridHorSteps = _desirableWidth / tileSize;
            _gridVerSteps = _desirableHeight / tileSize;

            var scale = Math.Min((float)_gridHorSteps / _image.Width, (float)_gridVerSteps / _image.Height);

            var scaleWidth = (_image.Width *  scale);
            var scaleHeight =(_image.Height * scale);

            var bmp = new Bitmap((int)scaleWidth, (int)scaleHeight);
            var graph = Graphics.FromImage(bmp);

            graph.InterpolationMode = InterpolationMode.High;
            graph.CompositingQuality = CompositingQuality.HighQuality;
            graph.SmoothingMode = SmoothingMode.HighQuality;

            graph.DrawImage(_image, 0, 0, scaleWidth, scaleHeight);

            bmp.Save("res1.jpg");

            _gridHorSteps = (int)scaleWidth;
            _gridVerSteps = (int)scaleHeight;

            _image = bmp;

            /*_desirableHeight = desirableHeight ;*/
            _avgColorCalculator = new AvgColorCalculator();
            _colorFilter = new ColorFilter(paletteTiles);

            _gridCellWidth = _image.Width / _gridHorSteps;
            _gridCellHeight = _image.Height / _gridVerSteps;
            _gridCellSize = new Size(_gridCellWidth, _gridCellHeight);
        }
Esempio n. 2
0
        private static void LoadContainer()
        {
            var directory = new DirectoryInfo("Tiles");

            var avgColorCalculator = new AvgColorCalculator();
            var i = 0;
            foreach (var tileImageFile in directory.GetFiles("*.jpg", SearchOption.TopDirectoryOnly))
            {
                var bitmap = new Bitmap(tileImageFile.FullName);

                /*            // hard code, because tile images has white surrounding area
                            var tileBitmap = new Bitmap(240, 240);
                            var g = Graphics.FromImage(tileBitmap);
                            g.DrawImage(bitmap, 0, 0, new Rectangle(145, 145, 240, 240), GraphicsUnit.Pixel);
                            tileBitmap.Save(string.Format("{0}.jpg", i));
                            i++;
                            //
            */
                var tileInfo = new TileInfo {TileBitmap = bitmap};
                tileInfo.Rgb = avgColorCalculator.Calculate(bitmap);
                tileInfo.Id = i++;
                TileBase.Add(tileInfo.Id, tileInfo);
            }
        }
        public ImageConverter(string imageFile, int tileSize, int desirableWidth, int desirableHeight)
        {
            _image = new Bitmap(imageFile);
            _tileSize = tileSize;
            _desirableWidth = desirableWidth;

            var ratio = (double)_image.Height / _image.Width;

            _desirableHeight = (int)(_desirableWidth * ratio);
            _avgColorCalculator = new AvgColorCalculator();
            _avgColorSearcher = new AvgColorSearcher();
            _gridHorSteps = _desirableWidth / tileSize;
            _gridVerSteps = _desirableHeight / tileSize;

            _gridCellWidth = _image.Width / _gridHorSteps;
            _gridCellHeight = _image.Height / _gridVerSteps;
            _gridCellSize = new Size(_gridCellWidth, _gridCellHeight);
        }