mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added CombineImages method
This commit is contained in:
parent
e442d7c6a1
commit
d7aa0ab7f5
4 changed files with 66 additions and 42 deletions
|
@ -1816,10 +1816,10 @@ public static string SaveImageFileDialog(Image img, string filePath = "", bool u
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap LoadImage(string filePath)
|
public static Bitmap LoadImage(string filePath)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(filePath))
|
if (!string.IsNullOrEmpty(filePath))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
filePath = Helpers.GetAbsolutePath(filePath);
|
filePath = Helpers.GetAbsolutePath(filePath);
|
||||||
|
|
||||||
|
@ -1836,11 +1836,11 @@ public static Bitmap LoadImage(string filePath)
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
DebugHelper.WriteException(e);
|
DebugHelper.WriteException(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1940,6 +1940,42 @@ public static Bitmap CombineImages(List<Bitmap> images, Orientation orientation
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap CombineImages(IEnumerable<string> imageFiles, Orientation orientation = Orientation.Vertical,
|
||||||
|
ImageCombinerAlignment alignment = ImageCombinerAlignment.LeftOrTop, int space = 0, bool autoFillBackground = false)
|
||||||
|
{
|
||||||
|
List<Bitmap> images = new List<Bitmap>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (string filePath in imageFiles)
|
||||||
|
{
|
||||||
|
Bitmap bmp = LoadImage(filePath);
|
||||||
|
|
||||||
|
if (bmp != null)
|
||||||
|
{
|
||||||
|
images.Add(bmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (images.Count > 1)
|
||||||
|
{
|
||||||
|
return CombineImages(images, orientation, alignment, space, autoFillBackground);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
foreach (Bitmap bmp in images)
|
||||||
|
{
|
||||||
|
if (bmp != null)
|
||||||
|
{
|
||||||
|
bmp.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Bitmap> SplitImage(Image img, int rowCount, int columnCount)
|
public static List<Bitmap> SplitImage(Image img, int rowCount, int columnCount)
|
||||||
{
|
{
|
||||||
List<Bitmap> images = new List<Bitmap>();
|
List<Bitmap> images = new List<Bitmap>();
|
||||||
|
|
|
@ -28,7 +28,7 @@ You should have received a copy of the GNU General Public License
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.MediaLib
|
namespace ShareX.MediaLib
|
||||||
|
@ -174,50 +174,25 @@ private void btnCombine_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (lvImages.Items.Count > 0)
|
if (lvImages.Items.Count > 0)
|
||||||
{
|
{
|
||||||
List<Bitmap> images = new List<Bitmap>();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (ListViewItem lvi in lvImages.Items)
|
List<string> imageFiles = lvImages.Items.Cast<ListViewItem>().Select(x => x.Text).ToList();
|
||||||
{
|
|
||||||
string filePath = lvi.Text;
|
|
||||||
|
|
||||||
if (File.Exists(filePath))
|
if (imageFiles.Count > 1)
|
||||||
{
|
{
|
||||||
Bitmap bmp = ImageHelpers.LoadImage(filePath);
|
Bitmap output = ImageHelpers.CombineImages(imageFiles, Options.Orientation, Options.Alignment, Options.Space, Options.AutoFillBackground);
|
||||||
|
|
||||||
if (bmp != null)
|
if (output != null)
|
||||||
{
|
{
|
||||||
images.Add(bmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (images.Count > 1)
|
|
||||||
{
|
|
||||||
Bitmap output = ImageHelpers.CombineImages(images, Options.Orientation, Options.Alignment, Options.Space, Options.AutoFillBackground);
|
|
||||||
|
|
||||||
OnProcessRequested(output);
|
OnProcessRequested(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
DebugHelper.WriteException(ex);
|
DebugHelper.WriteException(ex);
|
||||||
ex.ShowError();
|
ex.ShowError();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (images != null)
|
|
||||||
{
|
|
||||||
foreach (Bitmap image in images)
|
|
||||||
{
|
|
||||||
if (image != null)
|
|
||||||
{
|
|
||||||
image.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ public static void ExecuteJob(TaskSettings taskSettings, HotkeyType job, CLIComm
|
||||||
UploadManager.IndexFolder();
|
UploadManager.IndexFolder();
|
||||||
break;
|
break;
|
||||||
case HotkeyType.ImageCombiner:
|
case HotkeyType.ImageCombiner:
|
||||||
OpenImageCombiner(safeTaskSettings);
|
OpenImageCombiner(null, safeTaskSettings);
|
||||||
break;
|
break;
|
||||||
case HotkeyType.ImageSplitter:
|
case HotkeyType.ImageSplitter:
|
||||||
OpenImageSplitter();
|
OpenImageSplitter();
|
||||||
|
@ -841,7 +841,7 @@ public static void OpenDirectoryIndexer(TaskSettings taskSettings = null)
|
||||||
form.Show();
|
form.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OpenImageCombiner(TaskSettings taskSettings = null, IEnumerable<string> imageFiles = null)
|
public static void OpenImageCombiner(IEnumerable<string> imageFiles = null, TaskSettings taskSettings = null)
|
||||||
{
|
{
|
||||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
|
||||||
|
@ -850,6 +850,19 @@ public static void OpenImageCombiner(TaskSettings taskSettings = null, IEnumerab
|
||||||
imageCombinerForm.Show();
|
imageCombinerForm.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CombineImages(IEnumerable<string> imageFiles, Orientation orientation, TaskSettings taskSettings = null)
|
||||||
|
{
|
||||||
|
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||||
|
|
||||||
|
Bitmap output = ImageHelpers.CombineImages(imageFiles, orientation, taskSettings.ToolsSettings.ImageCombinerOptions.Alignment,
|
||||||
|
taskSettings.ToolsSettings.ImageCombinerOptions.Space, taskSettings.ToolsSettings.ImageCombinerOptions.AutoFillBackground);
|
||||||
|
|
||||||
|
if (output != null)
|
||||||
|
{
|
||||||
|
UploadManager.RunImageTask(output, taskSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void OpenImageSplitter()
|
public static void OpenImageSplitter()
|
||||||
{
|
{
|
||||||
ImageSplitterForm imageSplitterForm = new ImageSplitterForm();
|
ImageSplitterForm imageSplitterForm = new ImageSplitterForm();
|
||||||
|
|
|
@ -394,7 +394,7 @@ public void CombineImages()
|
||||||
|
|
||||||
if (imageFiles.Count() > 1)
|
if (imageFiles.Count() > 1)
|
||||||
{
|
{
|
||||||
TaskHelpers.OpenImageCombiner(null, imageFiles);
|
TaskHelpers.OpenImageCombiner(imageFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue