Make sure image is valid size

This commit is contained in:
Jaex 2019-12-08 16:39:23 +03:00
parent 32dd3cc77d
commit 9bcd554c43

View file

@ -28,6 +28,7 @@ You should have received a copy of the GNU General Public License
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
@ -90,13 +91,13 @@ public override Image Apply(Image img)
using (Graphics g = Graphics.FromImage(img))
using (ImageFilesCache imageCache = new ImageFilesCache())
{
g.SetHighQuality();
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
for (int i = 0; i < ImageCount; i++)
{
string randomFile = MathHelpers.RandomPick(files);
string file = MathHelpers.RandomPick(files);
Image img2 = imageCache.GetImage(randomFile);
Image img2 = imageCache.GetImage(file);
if (img2 != null)
{
@ -126,6 +127,11 @@ private void DrawImage(Image img, Image img2, Graphics g)
height = img2.Height;
}
if (width < 1 || height < 1)
{
return;
}
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);