mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 11:10:23 +12:00
Code refactoring
This commit is contained in:
parent
e4f0fce3f0
commit
365c2120ea
|
@ -2099,30 +2099,31 @@ public static Bitmap LoadImageWithFileDialog(Form form = null)
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Bitmap CombineImages(List<Bitmap> images, Orientation orientation = Orientation.Vertical,
|
||||
ImageCombinerAlignment alignment = ImageCombinerAlignment.LeftOrTop, int space = 0, bool autoFillBackground = false)
|
||||
public static Bitmap CombineImages(List<Bitmap> images, Orientation orientation, ImageCombinerAlignment alignment = ImageCombinerAlignment.LeftOrTop,
|
||||
int space = 0, bool autoFillBackground = false)
|
||||
{
|
||||
int width, height;
|
||||
int imageCount = images.Count;
|
||||
int spaceSize = space * (imageCount - 1);
|
||||
|
||||
if (orientation == Orientation.Vertical)
|
||||
{
|
||||
width = images.Max(x => x.Width);
|
||||
height = images.Sum(x => x.Height) + spaceSize;
|
||||
}
|
||||
else
|
||||
if (orientation == Orientation.Horizontal)
|
||||
{
|
||||
width = images.Sum(x => x.Width) + spaceSize;
|
||||
height = images.Max(x => x.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
width = images.Max(x => x.Width);
|
||||
height = images.Sum(x => x.Height) + spaceSize;
|
||||
}
|
||||
|
||||
Bitmap bmp = new Bitmap(width, height);
|
||||
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
g.SetHighQuality();
|
||||
int position = 0;
|
||||
|
||||
Point position = new Point(0, 0);
|
||||
|
||||
for (int i = 0; i < imageCount; i++)
|
||||
{
|
||||
|
@ -2135,44 +2136,45 @@ public static Bitmap LoadImageWithFileDialog(Form form = null)
|
|||
}
|
||||
|
||||
Rectangle rect;
|
||||
Point offset = new Point(0, 0);
|
||||
|
||||
if (orientation == Orientation.Vertical)
|
||||
if (orientation == Orientation.Horizontal)
|
||||
{
|
||||
int x;
|
||||
switch (alignment)
|
||||
{
|
||||
default:
|
||||
case ImageCombinerAlignment.LeftOrTop:
|
||||
x = 0;
|
||||
offset.Y = 0;
|
||||
break;
|
||||
case ImageCombinerAlignment.Center:
|
||||
x = (width / 2) - (image.Width / 2);
|
||||
offset.Y = (height / 2) - (image.Height / 2);
|
||||
break;
|
||||
case ImageCombinerAlignment.RightOrBottom:
|
||||
x = width - image.Width;
|
||||
offset.Y = height - image.Height;
|
||||
break;
|
||||
}
|
||||
rect = new Rectangle(x, position, image.Width, image.Height);
|
||||
position += image.Height + space;
|
||||
|
||||
rect = new Rectangle(position.X + offset.X, position.Y + offset.Y, image.Width, image.Height);
|
||||
position.X += image.Width + space;
|
||||
}
|
||||
else
|
||||
{
|
||||
int y;
|
||||
switch (alignment)
|
||||
{
|
||||
default:
|
||||
case ImageCombinerAlignment.LeftOrTop:
|
||||
y = 0;
|
||||
offset.X = 0;
|
||||
break;
|
||||
case ImageCombinerAlignment.Center:
|
||||
y = (height / 2) - (image.Height / 2);
|
||||
offset.X = (width / 2) - (image.Width / 2);
|
||||
break;
|
||||
case ImageCombinerAlignment.RightOrBottom:
|
||||
y = height - image.Height;
|
||||
offset.X = width - image.Width;
|
||||
break;
|
||||
}
|
||||
rect = new Rectangle(position, y, image.Width, image.Height);
|
||||
position += image.Width + space;
|
||||
|
||||
rect = new Rectangle(position.X + offset.X, position.Y + offset.Y, image.Width, image.Height);
|
||||
position.Y += image.Height + space;
|
||||
}
|
||||
|
||||
g.DrawImage(image, rect);
|
||||
|
@ -2182,8 +2184,8 @@ public static Bitmap LoadImageWithFileDialog(Form form = null)
|
|||
return bmp;
|
||||
}
|
||||
|
||||
public static Bitmap CombineImages(IEnumerable<string> imageFiles, Orientation orientation = Orientation.Vertical,
|
||||
ImageCombinerAlignment alignment = ImageCombinerAlignment.LeftOrTop, int space = 0, bool autoFillBackground = false)
|
||||
public static Bitmap CombineImages(IEnumerable<string> imageFiles, Orientation orientation, ImageCombinerAlignment alignment = ImageCombinerAlignment.LeftOrTop,
|
||||
int space = 0, bool autoFillBackground = false)
|
||||
{
|
||||
List<Bitmap> images = new List<Bitmap>();
|
||||
|
||||
|
|
|
@ -33,6 +33,6 @@ public class ImageCombinerOptions
|
|||
public Orientation Orientation { get; set; } = Orientation.Vertical;
|
||||
public ImageCombinerAlignment Alignment { get; set; } = ImageCombinerAlignment.LeftOrTop;
|
||||
public int Space { get; set; } = 0;
|
||||
public bool AutoFillBackground { get; set; } = false;
|
||||
public bool AutoFillBackground { get; set; } = true;
|
||||
}
|
||||
}
|
|
@ -608,7 +608,7 @@ private Bitmap CombineImages()
|
|||
output.Add(newImage);
|
||||
}
|
||||
|
||||
Bitmap bmpResult = ImageHelpers.CombineImages(output);
|
||||
Bitmap bmpResult = ImageHelpers.CombineImages(output, Orientation.Vertical);
|
||||
|
||||
foreach (Bitmap image in output)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue