public static Bitmap GenerateTargetImage(SourceImage sourceImage, AvailableImage[] availableImages, int targetBlockSize, string targetImagePath, Bitmap sourceBitmap) { var availableImagesCopy = availableImages.ToList(); var targetImage = CreateTargetImage(sourceImage, targetBlockSize); Console.WriteLine("Creating..."); var current = 0; var total = sourceImage.Blocks.Count(); var prevPercentage = 0; foreach (var sourcePixelBlock in sourceImage.Blocks) { current++; int percentage = current * 100 / total; if (prevPercentage != percentage) { Console.Write("\r" + (percentage + "%").PadRight(10)); prevPercentage = percentage; targetImage.Save(targetImagePath, sourceBitmap.RawFormat); } var matchingImage = FindBestMatchingImage(sourcePixelBlock, availableImagesCopy); if (availableImagesCopy.Count < 10) { availableImagesCopy = availableImages.ToList(); } UpdateBlock(targetImage, sourcePixelBlock, new TargetPixelGenerator(matchingImage, sourcePixelBlock)); } return(targetImage); }
public static void GenerateMosaicImage(string sourceImagePath, int sourceBlockSize, int blockTargetSize, string targetImagePath, AvailableImage[] originalAvailableImages) { Console.WriteLine(sourceImagePath); var sourceBitmap = new Bitmap(sourceImagePath); var resizedSource = new Bitmap(sourceBitmap, GetSourceFixedSize(sourceBitmap)); var blocks = new SourceImage(sourceBlockSize, resizedSource); var targetImage = GenerateTargetImage(blocks, originalAvailableImages, blockTargetSize, targetImagePath, sourceBitmap); targetImage.SetResolution(220, 220); targetImage.Save(targetImagePath, sourceBitmap.RawFormat); }
private static Bitmap CreateTargetImage(SourceImage sourceImage, int targetBlockSize) { return(new Bitmap(sourceImage.NumBlocksX * targetBlockSize, sourceImage.NumBlocksY * targetBlockSize)); }