Skip to content

Commit

Permalink
Added image effects hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaex authored and Jaex committed Nov 20, 2013
1 parent d3c110b commit 4f2c96c
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion HelpersLib/Forms/ImageViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void ShowImage(string filepath)
{
if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath))
{
using (Image img = Helpers.GetImageFromFile(filepath))
using (Image img = ImageHelpers.LoadImage(filepath))
using (ImageViewer viewer = new ImageViewer(img))
{
viewer.ShowDialog();
Expand Down
2 changes: 1 addition & 1 deletion HelpersLib/GIF/AnimatedGif.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void AddFrame(Image img)

public void AddFrame(string path)
{
using (Image img = Helpers.GetImageFromFile(path))
using (Image img = ImageHelpers.LoadImage(path))
{
AddFrame(img);
}
Expand Down
2 changes: 1 addition & 1 deletion HelpersLib/GIF/GifCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void AddFrame(Image img, GIFQuality quality = GIFQuality.Default)

public void AddFrame(string path, GIFQuality quality = GIFQuality.Default)
{
using (Image img = Helpers.GetImageFromFile(path))
using (Image img = ImageHelpers.LoadImage(path))
{
AddFrame(img, quality);
}
Expand Down
2 changes: 1 addition & 1 deletion HelpersLib/Helpers/ClipboardHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static bool CopyImageFromFile(string path)
{
try
{
using (Image img = Helpers.GetImageFromFile(path))
using (Image img = ImageHelpers.LoadImage(path))
{
return CopyImage(img);
}
Expand Down
11 changes: 0 additions & 11 deletions HelpersLib/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,6 @@ public static EDataType FindDataType(string filePath)
return EDataType.File;
}

// http://stackoverflow.com/questions/788335/why-does-image-fromfile-keep-a-file-handle-open-sometimes
public static Image GetImageFromFile(string filePath)
{
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
return Image.FromStream(new MemoryStream(File.ReadAllBytes(filePath)));
}

return null;
}

public static string AddZeroes(int number, int digits = 2)
{
return number.ToString().PadLeft(digits, '0');
Expand Down
11 changes: 11 additions & 0 deletions HelpersLib/Helpers/ImageHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,5 +1014,16 @@ public static void SaveImageFileDialog(Image img)
}
}
}

// http://stackoverflow.com/questions/788335/why-does-image-fromfile-keep-a-file-handle-open-sometimes
public static Image LoadImage(string filePath)
{
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
return Image.FromStream(new MemoryStream(File.ReadAllBytes(filePath)));
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion HelpersLib/UserControls/MyPictureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void LoadImageFromFile(string filePath)
{
isImageLoading = true;
Reset();
Image = Helpers.GetImageFromFile(filePath);
Image = ImageHelpers.LoadImage(filePath);
AutoSetSizeMode();
isImageLoading = false;
}
Expand Down
2 changes: 1 addition & 1 deletion ImageEffectsLib/Drawings/DrawImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override Image Apply(Image img)
{
if (!string.IsNullOrEmpty(ImageLocation) && File.Exists(ImageLocation))
{
using (Image img2 = Helpers.GetImageFromFile(ImageLocation))
using (Image img2 = ImageHelpers.LoadImage(ImageLocation))
{
Point imagePosition = Helpers.GetPosition(Placement, Offset, img.Size, img2.Size);
Rectangle imageRectangle = new Rectangle(imagePosition, img2.Size);
Expand Down
17 changes: 10 additions & 7 deletions ImageEffectsLib/ImageEffectsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ private void AddEffectToTreeView(string groupName, params Type[] imageEffects)

private void UpdatePreview()
{
Stopwatch timer = Stopwatch.StartNew();

using (Image preview = ApplyEffects())
if (DefaultImage != null)
{
pbResult.LoadImage(preview);
Text = string.Format("ShareX - Image effects - Width: {0}, Height: {1}, Render time: {2} ms", preview.Width, preview.Height, timer.ElapsedMilliseconds);
Stopwatch timer = Stopwatch.StartNew();

using (Image preview = ApplyEffects())
{
pbResult.LoadImage(preview);
Text = string.Format("ShareX - Image effects - Width: {0}, Height: {1}, Render time: {2} ms", preview.Width, preview.Height, timer.ElapsedMilliseconds);
}
}
}

Expand Down Expand Up @@ -345,7 +348,7 @@ private void btnLoadImage_Click(object sender, EventArgs e)
if (!string.IsNullOrEmpty(filePath))
{
if (DefaultImage != null) DefaultImage.Dispose();
DefaultImage = Helpers.GetImageFromFile(filePath);
DefaultImage = ImageHelpers.LoadImage(filePath);
UpdatePreview();
}
}
Expand Down Expand Up @@ -381,7 +384,7 @@ private void pbResult_DragDrop(object sender, DragEventArgs e)
if (Helpers.IsImageFile(files[0]))
{
if (DefaultImage != null) DefaultImage.Dispose();
DefaultImage = Helpers.GetImageFromFile(files[0]);
DefaultImage = ImageHelpers.LoadImage(files[0]);
UpdatePreview();
}
}
Expand Down
4 changes: 3 additions & 1 deletion ShareX/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ public enum HotkeyType
[Description("Hash check")]
HashCheck,
[Description("Index folder")]
IndexFolder
IndexFolder,
[Description("Image effects")]
ImageEffects
}

public enum HotkeyStatus
Expand Down
13 changes: 13 additions & 0 deletions ShareX/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,19 @@ private void OpenIndexFolder()
UploadManager.IndexFolder();
}

private void OpenImageEffects()
{
string filePath = ImageHelpers.OpenImageFileDialog();

if (!string.IsNullOrEmpty(filePath))
{
Image img = ImageHelpers.LoadImage(filePath);
ImageEffectsForm form = new ImageEffectsForm(img);
form.EditorMode();
form.Show();
}
}

#region Form events

protected override void SetVisibleCore(bool value)
Expand Down
3 changes: 3 additions & 0 deletions ShareX/Forms/MainForm_Capture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ private void HandleHotkeys(HotkeySettings hotkeySetting)
case HotkeyType.IndexFolder:
OpenIndexFolder();
break;
case HotkeyType.ImageEffects:
OpenImageEffects();
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ShareX/UploadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static UploadTask CreateFileUploaderTask(string filePath, TaskSettings ta
if (task.Info.TaskSettings.AdvancedSettings.ProcessImagesDuringFileUpload && dataType == EDataType.Image)
{
task.Info.Job = TaskJob.ImageJob;
task.tempImage = Helpers.GetImageFromFile(filePath);
task.tempImage = ImageHelpers.LoadImage(filePath);
}
else
{
Expand Down

0 comments on commit 4f2c96c

Please sign in to comment.