/// <summary> /// Creates the triangle mosaic. /// </summary> /// <param name="blockSize">Size of the block.</param> public void CreateTriangleMosaic(int blockSize) { foreach (var index in this.getBlockStartingPoints(blockSize)) { var indexMapperData = IndexMapper.Triangle(index, blockSize, (int)this.ImageWidth, (int)this.ImageHeight); for (var collectionIndex = 0; collectionIndex < indexMapperData.Count; collectionIndex++) { IndexMapper.ConvertEachIndexToMatchOffset(indexMapperData[collectionIndex], 4); } var left = indexMapperData[0]; var right = indexMapperData[1]; if (left.Length > 0) { Painter.FillWithAverageColor(this.SourcePixels, left); } if (right.Length > 0) { Painter.FillWithAverageColor(this.SourcePixels, right); } } }
/// <summary> /// Creates the solid block mosaic with the specified block sizes /// </summary> /// <param name="blockSize"> the block size to use</param> public void CreateSquareMosaic(int blockSize) { foreach (var index in this.getBlockStartingPoints(blockSize)) { var indexes = IndexMapper.Box(index, blockSize, (int)this.ImageWidth, (int)this.ImageHeight); IndexMapper.ConvertEachIndexToMatchOffset(indexes, 4); Painter.FillWithAverageColor(this.SourcePixels, indexes); } }
/// <summary> /// Draws the grid. /// </summary> /// <param name="blockSize">Size of the block.</param> /// <param name="includeDiagonalLine">if set to <c>true</c> [include diagonal line].</param> public void DrawGrid(int blockSize, bool includeDiagonalLine) { foreach (var index in this.getBlockStartingPoints(blockSize)) { var indexes = IndexMapper.Grid(index, blockSize, (int)this.ImageWidth, (int)this.ImageHeight, includeDiagonalLine); IndexMapper.ConvertEachIndexToMatchOffset(indexes, 4); Painter.FillWithColor(this.SourcePixels, indexes, Color.FromArgb(255, 255, 255, 255)); } }
/// <summary> /// Creates a picture mosaic with the specified block size and image palette /// </summary> /// <param name="blockSize"> the block size </param> /// <param name="palette"> the palette to use</param> /// <param name="juxtaposition"> whether to juxtaposition the picture to prevent patterns</param> /// /// /// <param name="cycle"> /// whether to cycle through available photos to ensure no photo used used more that once more than /// any other /// </param> public async Task CreatePictureMosaic(int blockSize, ImagePalette palette, bool juxtaposition, bool cycle) { if (palette.AverageColorDictionary.Count == 0) { throw new ArgumentException("There must be a minimum of one picture in the palette.", nameof(palette)); } if (juxtaposition && cycle && palette.AverageColorDictionary.Count < 1) { throw new ArgumentException( "There must be at least two pictures in the palette to both cycle thorough images and prevent juxtaposition", nameof(palette)); } var colors = palette.AverageColorDictionary; var cycleRemoved = new Collection <Image>(); var disqualified = new Collection <Image>(); var previous = new Collection <Image>(); var tasks = new Collection <Task>(); var aboveImageIndex = 0; var imageByteWidth = (int)this.ImageWidth * 4; Image aboveImage = null; foreach (var index in this.getBlockStartingPoints(blockSize)) { var indexes = IndexMapper.Box(index, blockSize, (int)this.ImageWidth, (int)this.ImageHeight); IndexMapper.ConvertEachIndexToMatchOffset(indexes, 4); var averageColor = Painter.GetAverageColor(this.SourcePixels, indexes); Image imageToUse = null; if (juxtaposition) { if (index > imageByteWidth) { aboveImage = previous[aboveImageIndex]; aboveImageIndex++; } imageToUse = this.getRandomImage(indexes, palette, aboveImage, previous, disqualified, cycleRemoved); } if (cycle) { if (imageToUse == null) { imageToUse = findClosestMatch(colors, averageColor, cycleRemoved); } cycleRemoved.Add(imageToUse); if (cycleRemoved.Count == colors.Count) { cycleRemoved.Clear(); } } if (imageToUse == null) { imageToUse = findClosestMatch(colors, averageColor, cycleRemoved); } var task = await Task.Factory.StartNew(async() => { await imageToUse.ResizeImage(blockSize); Painter.FillBlockWithPicture(this.SourcePixels, imageToUse.ModifiedPixels, indexes); }); tasks.Add(task); } foreach (var task in tasks) { await task; } }