public TileImage(LibraryImage image, MosaicTile tile)
 {
     Image = image;
     FilePath = System.Configuration.ConfigurationManager.AppSettings["ProcessedImageLibraryDirectory"] + image.FileName;
     Tile = tile;
     PosX = tile.PosX;
     PosY = tile.PosY;
     TileWidth = tile.TileHeight;
     TileHeight = tile.TileHeight;
 }
        public TileImage CreateTileImage(MosaicTile tile, List<LibraryImage> libraryImages)
        {
            // Get the closest image
            LibraryImage closestImage = new LibraryImage();
            double closestDelta = double.MaxValue;

            foreach (var libraryImage in libraryImages)
            {
                double delta = ComputeColorDifference(tile.AverageColor, libraryImage.AverageColor);
                if (delta < closestDelta)
                {
                    closestDelta = delta;
                    closestImage = libraryImage;
                }
            }

            return new TileImage(closestImage, tile);
        }