AnnotateImage method moved to ShareX project from HelpersLib project

This commit is contained in:
Jaex 2016-11-14 00:19:26 +03:00
parent 91714d3235
commit 3f2ed7f11b
4 changed files with 51 additions and 87 deletions

View file

@ -23,37 +23,6 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
#region License Information (Greenshot)
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2013 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion License Information (Greenshot)
using Greenshot;
using Greenshot.Drawing;
using Greenshot.IniFile;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using GreenshotPlugin.UnmanagedHelpers;
using System;
using System.Collections.Generic;
using System.Drawing;
@ -1472,54 +1441,5 @@ public static void DrawColorPickerIcon(Graphics g, Color color, Rectangle rect,
g.DrawRectangleProper(Pens.Black, holeRect);
}
}
#region Greenshot methods
public static Image AnnotateImage(Image img, string imgPath, bool allowSave, string configPath,
Action<Image> clipboardCopyRequested,
Action<Image> imageUploadRequested,
Action<Image, string> imageSaveRequested,
Func<Image, string, string> imageSaveAsRequested,
Action<Image> printImageRequested)
{
if (!IniConfig.isInitialized)
{
IniConfig.AllowSave = allowSave;
IniConfig.Init(configPath);
}
using (Image cloneImage = img != null ? (Image)img.Clone() : LoadImage(imgPath))
using (ICapture capture = new Capture { Image = cloneImage })
using (Surface surface = new Surface(capture))
using (ImageEditorForm editor = new ImageEditorForm(surface, true))
{
editor.IsTaskWork = img != null;
editor.SetImagePath(imgPath);
editor.ClipboardCopyRequested += clipboardCopyRequested;
editor.ImageUploadRequested += imageUploadRequested;
editor.ImageSaveRequested += imageSaveRequested;
editor.ImageSaveAsRequested += imageSaveAsRequested;
editor.PrintImageRequested += printImageRequested;
DialogResult result = editor.ShowDialog();
if (result == DialogResult.OK && editor.IsTaskWork)
{
using (img)
{
return editor.GetImageForExport();
}
}
if (result == DialogResult.Abort)
{
return null;
}
}
return img;
}
#endregion Greenshot methods
}
}

View file

@ -1157,12 +1157,6 @@
<ItemGroup>
<None Include="Resources\Crosshair.cur" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Greenshot.ImageEditor\Greenshot.ImageEditor.csproj">
<Project>{cd642bf4-d815-4d67-a0b5-c69f0b8231af}</Project>
<Name>Greenshot.ImageEditor</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\ShareX_Icon.ico" />
</ItemGroup>

View file

@ -1082,6 +1082,10 @@
<EmbeddedResource Include="Properties\Resources.zh-CN.resx" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Greenshot.ImageEditor\Greenshot.ImageEditor.csproj">
<Project>{cd642bf4-d815-4d67-a0b5-c69f0b8231af}</Project>
<Name>Greenshot.ImageEditor</Name>
</ProjectReference>
<ProjectReference Include="..\ShareX.HistoryLib\ShareX.HistoryLib.csproj">
<Project>{E7DE6237-AEA2-498B-8F56-9B392472C490}</Project>
<Name>ShareX.HistoryLib</Name>

View file

@ -23,6 +23,11 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using Greenshot;
using Greenshot.Drawing;
using Greenshot.IniFile;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using ShareX.HelpersLib;
using ShareX.HistoryLib;
using ShareX.ImageEffectsLib;
@ -832,7 +837,7 @@ public static void AnnotateImageUsingShareX(Image img, string filePath, TaskSett
public static Image AnnotateImageUsingGreenshot(Image img, string imgPath)
{
return ImageHelpers.AnnotateImage(img, imgPath, !Program.Sandbox, Program.PersonalFolder,
return AnnotateImageUsingGreenshot(img, imgPath, !Program.Sandbox, Program.PersonalFolder,
x => Program.MainForm.InvokeSafe(() => ClipboardHelpers.CopyImage(x)),
x => Program.MainForm.InvokeSafe(() => UploadManager.UploadImage(x)),
(x, filePath) => Program.MainForm.InvokeSafe(() => ImageHelpers.SaveImage(x, filePath)),
@ -845,6 +850,47 @@ public static Image AnnotateImageUsingGreenshot(Image img, string imgPath)
x => Program.MainForm.InvokeSafe(() => PrintImage(x)));
}
private static Image AnnotateImageUsingGreenshot(Image img, string imgPath, bool allowSave, string configPath, Action<Image> clipboardCopyRequested,
Action<Image> imageUploadRequested, Action<Image, string> imageSaveRequested, Func<Image, string, string> imageSaveAsRequested, Action<Image> printImageRequested)
{
if (!IniConfig.isInitialized)
{
IniConfig.AllowSave = allowSave;
IniConfig.Init(configPath);
}
using (Image cloneImage = img != null ? (Image)img.Clone() : ImageHelpers.LoadImage(imgPath))
using (ICapture capture = new Capture { Image = cloneImage })
using (Surface surface = new Surface(capture))
using (ImageEditorForm editor = new ImageEditorForm(surface, true))
{
editor.IsTaskWork = img != null;
editor.SetImagePath(imgPath);
editor.ClipboardCopyRequested += clipboardCopyRequested;
editor.ImageUploadRequested += imageUploadRequested;
editor.ImageSaveRequested += imageSaveRequested;
editor.ImageSaveAsRequested += imageSaveAsRequested;
editor.PrintImageRequested += printImageRequested;
DialogResult result = editor.ShowDialog();
if (result == DialogResult.OK && editor.IsTaskWork)
{
using (img)
{
return editor.GetImageForExport();
}
}
if (result == DialogResult.Abort)
{
return null;
}
}
return img;
}
public static void OpenImageEffects()
{
string filePath = ImageHelpers.OpenImageFileDialog();