public override Bitmap Apply(Bitmap bmp) { string imageFolder = Helpers.ExpandFolderVariables(ImageFolder); if (!string.IsNullOrEmpty(imageFolder) && Directory.Exists(imageFolder)) { string[] files = Helpers.GetFilesByExtensions(imageFolder, ".png", ".jpg").ToArray(); if (files.Length > 0) { imageRectangles.Clear(); using (Graphics g = Graphics.FromImage(bmp)) using (ImageFilesCache imageCache = new ImageFilesCache()) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; for (int i = 0; i < ImageCount; i++) { string file = MathHelpers.RandomPick(files); Bitmap bmpCached = imageCache.GetImage(file); if (bmpCached != null) { DrawImage(bmp, bmpCached, g); } } } } } return(bmp); }
public override Image Apply(Image img) { string imageFolder = Helpers.ExpandFolderVariables(ImageFolder); if (!string.IsNullOrEmpty(imageFolder) && Directory.Exists(imageFolder)) { string[] files = Helpers.GetFilesByExtensions(imageFolder, ".png", ".jpg").ToArray(); if (files.Length > 0) { using (Graphics g = Graphics.FromImage(img)) using (ImageFilesCache imageCache = new ImageFilesCache()) { g.SetHighQuality(); for (int i = 0; i < ImageCount; i++) { string randomFile = MathHelpers.RandomPick(files); Image img2 = imageCache.GetImage(randomFile); if (img2 != null) { int xOffset = img.Width - img2.Width - 1; int yOffset = img.Height - img2.Height - 1; int width, height; if (RandomSize) { width = height = MathHelpers.Random(Math.Min(RandomSizeMin, RandomSizeMax), Math.Max(RandomSizeMin, RandomSizeMax)); } else { width = img2.Width; height = img2.Height; } Rectangle rect = new Rectangle(MathHelpers.Random(Math.Min(0, xOffset), Math.Max(0, xOffset)), MathHelpers.Random(Math.Min(0, yOffset), Math.Max(0, yOffset)), width, height); if (RandomRotate) { float moveX = rect.X + (rect.Width / 2f); float moveY = rect.Y + (rect.Height / 2f); g.TranslateTransform(moveX, moveY); g.RotateTransform(MathHelpers.Random(0, 360)); g.TranslateTransform(-moveX, -moveY); } g.DrawImage(img2, rect); if (RandomRotate) { g.ResetTransform(); } } } } } } return(img); }