mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 10:47:02 -07:00
Made the supported image formats extendable, and supplied a SVG implementation right away with the jira addon.
This commit is contained in:
parent
9bf9c0e4e6
commit
fc192827f1
21 changed files with 1354 additions and 676 deletions
|
@ -95,6 +95,7 @@
|
|||
<Compile Include="Log4NetLogger.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SvgBitmapHttpContentConverter.cs" />
|
||||
<Compile Include="SvgImage.cs" />
|
||||
<None Include="Languages\language_jiraplugin-de-DE.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
|
@ -118,12 +118,12 @@ namespace GreenshotJiraPlugin {
|
|||
{
|
||||
var surfaceContainer = new SurfaceContainer(surfaceToUpload, outputSettings, filename);
|
||||
await _jiraPlugin.JiraConnector.AttachAsync(_jiraIssue.Key, surfaceContainer);
|
||||
surfaceToUpload.UploadURL = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri;
|
||||
surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri;
|
||||
}
|
||||
);
|
||||
Log.DebugFormat("Uploaded to Jira {0}", _jiraIssue.Key);
|
||||
exportInformation.ExportMade = true;
|
||||
exportInformation.Uri = surfaceToUpload.UploadURL;
|
||||
exportInformation.Uri = surfaceToUpload.UploadUrl;
|
||||
} catch (Exception e) {
|
||||
MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ namespace GreenshotJiraPlugin {
|
|||
var dialogResult = jiraForm.ShowDialog();
|
||||
if (dialogResult == DialogResult.OK) {
|
||||
try {
|
||||
surfaceToUpload.UploadURL = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", jiraForm.GetJiraIssue().Key).AbsoluteUri;
|
||||
surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", jiraForm.GetJiraIssue().Key).AbsoluteUri;
|
||||
// Run upload in the background
|
||||
new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
|
||||
async () =>
|
||||
|
@ -143,7 +143,7 @@ namespace GreenshotJiraPlugin {
|
|||
);
|
||||
Log.DebugFormat("Uploaded to Jira {0}", jiraForm.GetJiraIssue().Key);
|
||||
exportInformation.ExportMade = true;
|
||||
exportInformation.Uri = surfaceToUpload.UploadURL;
|
||||
exportInformation.Uri = surfaceToUpload.UploadUrl;
|
||||
} catch(Exception e) {
|
||||
MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
|
||||
}
|
||||
|
|
|
@ -23,9 +23,13 @@ using System.Windows.Forms;
|
|||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Threading.Tasks;
|
||||
using Dapplo.Log.Facade;
|
||||
using GreenshotJiraPlugin.Forms;
|
||||
using GreenshotPlugin.Core;
|
||||
using Svg;
|
||||
|
||||
namespace GreenshotJiraPlugin {
|
||||
/// <summary>
|
||||
|
@ -95,6 +99,21 @@ namespace GreenshotJiraPlugin {
|
|||
_config = IniConfig.GetIniSection<JiraConfiguration>();
|
||||
LogSettings.RegisterDefaultLogger<Log4NetLogger>();
|
||||
|
||||
// Add a SVG converter, although it doesn't fit to the Jira plugin there is currently no other way
|
||||
ImageHelper.StreamConverters["svg"] = (stream, s) =>
|
||||
{
|
||||
stream.Position = 0;
|
||||
try
|
||||
{
|
||||
return SvgImage.FromStream(stream).Image;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Can't load SVG", ex);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -33,8 +32,6 @@ using Dapplo.HttpExtensions.Support;
|
|||
using Dapplo.Log.Facade;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using GreenshotPlugin.Core;
|
||||
using Svg;
|
||||
|
||||
namespace GreenshotJiraPlugin
|
||||
{
|
||||
|
@ -86,12 +83,12 @@ namespace GreenshotJiraPlugin
|
|||
using (var memoryStream = (MemoryStream) await StreamHttpContentConverter.Instance.ConvertFromHttpContentAsync(typeof(MemoryStream), httpContent, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
Log.Debug().WriteLine("Creating a Bitmap from the SVG.");
|
||||
var bitmap = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent, 96, 96);
|
||||
var svgDoc = SvgDocument.Open<SvgDocument>(memoryStream);
|
||||
svgDoc.Width = Width;
|
||||
svgDoc.Height = Height;
|
||||
svgDoc.Draw(bitmap);
|
||||
return bitmap;
|
||||
var svgImage = new SvgImage(memoryStream)
|
||||
{
|
||||
Height = Height,
|
||||
Width = Width
|
||||
};
|
||||
return svgImage.Image;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
118
GreenshotJiraPlugin/SvgImage.cs
Normal file
118
GreenshotJiraPlugin/SvgImage.cs
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on GitHub https://github.com/greenshot/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/>.
|
||||
*/
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using GreenshotPlugin.Core;
|
||||
using Svg;
|
||||
|
||||
namespace GreenshotJiraPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Create an image look like of the SVG
|
||||
/// </summary>
|
||||
public class SvgImage : IImage
|
||||
{
|
||||
private readonly SvgDocument _svgDocument;
|
||||
|
||||
private Image _imageClone;
|
||||
|
||||
/// <summary>
|
||||
/// Factory to create via a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream</param>
|
||||
/// <returns>IImage</returns>
|
||||
public static IImage FromStream(Stream stream)
|
||||
{
|
||||
return new SvgImage(stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
/// <param name="stream"></param>
|
||||
public SvgImage(Stream stream)
|
||||
{
|
||||
_svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
||||
Height = (int)_svgDocument.ViewBox.Height;
|
||||
Width = (int)_svgDocument.ViewBox.Width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Height of the image, can be set to change
|
||||
/// </summary>
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Width of the image, can be set to change.
|
||||
/// </summary>
|
||||
public int Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of the image
|
||||
/// </summary>
|
||||
public Size Size => new Size(Width, Height);
|
||||
|
||||
/// <summary>
|
||||
/// Pixelformat of the underlying image
|
||||
/// </summary>
|
||||
public PixelFormat PixelFormat => Image.PixelFormat;
|
||||
|
||||
/// <summary>
|
||||
/// Horizontal resolution of the underlying image
|
||||
/// </summary>
|
||||
public float HorizontalResolution => Image.HorizontalResolution;
|
||||
|
||||
/// <summary>
|
||||
/// Vertical resolution of the underlying image
|
||||
/// </summary>
|
||||
public float VerticalResolution => Image.VerticalResolution;
|
||||
|
||||
/// <summary>
|
||||
/// Unterlying image, or an on demand rendered version with different attributes as the original
|
||||
/// </summary>
|
||||
public Image Image
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_imageClone?.Height == Height && _imageClone?.Width == Width)
|
||||
{
|
||||
return _imageClone;
|
||||
}
|
||||
// Calculate new image clone
|
||||
_imageClone?.Dispose();
|
||||
_imageClone = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent, 96, 96);
|
||||
_svgDocument.Draw((Bitmap)_imageClone);
|
||||
return _imageClone;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_imageClone?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue