mirror of
https://github.com/greenshot/greenshot
synced 2025-08-23 06:36:20 -07:00
Code Quality changes and dependency updates.
This commit is contained in:
parent
1a23227c68
commit
6b6bcb99bb
123 changed files with 3092 additions and 3781 deletions
|
@ -58,11 +58,11 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="!$(MSBuildProjectName.Contains('Tests')) And $(MSBuildProjectName.StartsWith('Greenshot'))">
|
<ItemGroup Condition="!$(MSBuildProjectName.Contains('Tests')) And $(MSBuildProjectName.StartsWith('Greenshot'))">
|
||||||
<PackageReference Include="Nerdbank.GitVersioning" Version="3.0.26">
|
<PackageReference Include="Nerdbank.GitVersioning" Version="3.0.28">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19351-01" PrivateAssets="All"/>
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" BeforeTargets="PostBuildEvent" Condition="'$(BuildingInsideVisualStudio)' == 'true' And $(MSBuildProjectName.Contains('Addon.')) And !$(MSBuildProjectName.Contains('Test')) And !$(MSBuildProjectName.Contains('Demo'))">
|
<Target Name="PostBuild" BeforeTargets="PostBuildEvent" Condition="'$(BuildingInsideVisualStudio)' == 'true' And $(MSBuildProjectName.Contains('Addon.')) And !$(MSBuildProjectName.Contains('Test')) And !$(MSBuildProjectName.Contains('Demo'))">
|
||||||
|
|
|
@ -119,12 +119,10 @@ namespace Greenshot.Addon.Box
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this
|
// TODO: Optimize this
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "box.png"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "box.png");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
||||||
|
@ -164,12 +162,10 @@ namespace Greenshot.Addon.Box
|
||||||
|
|
||||||
if (url != null && _boxConfiguration.AfterUploadLinkToClipBoard)
|
if (url != null && _boxConfiguration.AfterUploadLinkToClipBoard)
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(url);
|
clipboardAccessToken.SetAsUrl(url);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -206,8 +202,7 @@ namespace Greenshot.Addon.Box
|
||||||
oauthHttpBehaviour.OnHttpMessageHandlerCreated = httpMessageHandler => new OAuth2HttpMessageHandler(_oauth2Settings, oauthHttpBehaviour, httpMessageHandler);
|
oauthHttpBehaviour.OnHttpMessageHandlerCreated = httpMessageHandler => new OAuth2HttpMessageHandler(_oauth2Settings, oauthHttpBehaviour, httpMessageHandler);
|
||||||
|
|
||||||
// TODO: See if the PostAsync<Bitmap> can be used? Or at least the HttpContentFactory?
|
// TODO: See if the PostAsync<Bitmap> can be used? Or at least the HttpContentFactory?
|
||||||
using (var imageStream = new MemoryStream())
|
using var imageStream = new MemoryStream();
|
||||||
{
|
|
||||||
var multiPartContent = new MultipartFormDataContent();
|
var multiPartContent = new MultipartFormDataContent();
|
||||||
var parentIdContent = new StringContent(_boxConfiguration.FolderId);
|
var parentIdContent = new StringContent(_boxConfiguration.FolderId);
|
||||||
parentIdContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
parentIdContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
||||||
|
@ -258,7 +253,6 @@ namespace Greenshot.Addon.Box
|
||||||
}
|
}
|
||||||
return $"http://www.box.com/files/0/f/0/1/f_{response.Id}";
|
return $"http://www.box.com/files/0/f/0/1/f_{response.Id}";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -125,12 +125,10 @@ namespace Greenshot.Addon.Dropbox
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this by caching
|
// TODO: Optimize this by caching
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "Dropbox.gif"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "Dropbox.gif");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string Description => _dropboxLanguage.UploadMenuItem;
|
public override string Description => _dropboxLanguage.UploadMenuItem;
|
||||||
|
@ -146,12 +144,10 @@ namespace Greenshot.Addon.Dropbox
|
||||||
exportInformation.ExportMade = true;
|
exportInformation.ExportMade = true;
|
||||||
if (_dropboxPluginConfiguration.AfterUploadLinkToClipBoard)
|
if (_dropboxPluginConfiguration.AfterUploadLinkToClipBoard)
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(uploadUrl);
|
clipboardAccessToken.SetAsUrl(uploadUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_exportNotification.NotifyOfExport(this, exportInformation, surface);
|
_exportNotification.NotifyOfExport(this, exportInformation, surface);
|
||||||
return exportInformation;
|
return exportInformation;
|
||||||
|
@ -166,30 +162,24 @@ namespace Greenshot.Addon.Dropbox
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var cancellationTokenSource = new CancellationTokenSource();
|
var cancellationTokenSource = new CancellationTokenSource();
|
||||||
using (var ownedPleaseWaitForm = _pleaseWaitFormFactory(cancellationTokenSource))
|
using var ownedPleaseWaitForm = _pleaseWaitFormFactory(cancellationTokenSource);
|
||||||
{
|
|
||||||
ownedPleaseWaitForm.Value.SetDetails("Dropbox", _dropboxLanguage.CommunicationWait);
|
ownedPleaseWaitForm.Value.SetDetails("Dropbox", _dropboxLanguage.CommunicationWait);
|
||||||
ownedPleaseWaitForm.Value.Show();
|
ownedPleaseWaitForm.Value.Show();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var filename = surfaceToUpload.GenerateFilename(CoreConfiguration, _dropboxPluginConfiguration);
|
var filename = surfaceToUpload.GenerateFilename(CoreConfiguration, _dropboxPluginConfiguration);
|
||||||
using (var imageStream = new MemoryStream())
|
using var imageStream = new MemoryStream();
|
||||||
{
|
|
||||||
surfaceToUpload.WriteToStream(imageStream, CoreConfiguration, _dropboxPluginConfiguration);
|
surfaceToUpload.WriteToStream(imageStream, CoreConfiguration, _dropboxPluginConfiguration);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
using (var streamContent = new StreamContent(imageStream))
|
using var streamContent = new StreamContent(imageStream);
|
||||||
{
|
|
||||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue(surfaceToUpload.GenerateMimeType(CoreConfiguration, _dropboxPluginConfiguration));
|
streamContent.Headers.ContentType = new MediaTypeHeaderValue(surfaceToUpload.GenerateMimeType(CoreConfiguration, _dropboxPluginConfiguration));
|
||||||
dropboxUrl = await UploadAsync(filename, streamContent, null, cancellationToken).ConfigureAwait(false);
|
dropboxUrl = await UploadAsync(filename, streamContent, null, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
ownedPleaseWaitForm.Value.Close();
|
ownedPleaseWaitForm.Value.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error().WriteLine(e);
|
Log.Error().WriteLine(e);
|
||||||
|
|
|
@ -89,13 +89,11 @@ namespace Greenshot.Addon.ExternalCommand
|
||||||
{
|
{
|
||||||
exportInformation.Uri = uriMatches[0].Groups[1].Value;
|
exportInformation.Uri = uriMatches[0].Groups[1].Value;
|
||||||
|
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(exportInformation.Uri);
|
clipboardAccessToken.SetAsUrl(exportInformation.Uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (_externalCommandDefinition.CommandBehavior.HasFlag(CommandBehaviors.DeleteOnExit))
|
if (_externalCommandDefinition.CommandBehavior.HasFlag(CommandBehaviors.DeleteOnExit))
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CliWrap" Version="2.4.0" />
|
<PackageReference Include="CliWrap" Version="2.5.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -125,12 +125,10 @@ namespace Greenshot.Addon.Flickr
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this by caching
|
// TODO: Optimize this by caching
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "flickr.png"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "flickr.png");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
||||||
{
|
{
|
||||||
|
@ -175,12 +173,10 @@ namespace Greenshot.Addon.Flickr
|
||||||
}
|
}
|
||||||
if (_flickrConfiguration.AfterUploadLinkToClipBoard)
|
if (_flickrConfiguration.AfterUploadLinkToClipBoard)
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(uploadUrl);
|
clipboardAccessToken.SetAsUrl(uploadUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -222,8 +218,7 @@ namespace Greenshot.Addon.Flickr
|
||||||
{
|
{
|
||||||
surfaceToUpload.WriteToStream(stream, CoreConfiguration, _flickrConfiguration);
|
surfaceToUpload.WriteToStream(stream, CoreConfiguration, _flickrConfiguration);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
using (var streamContent = new StreamContent(stream))
|
using var streamContent = new StreamContent(stream);
|
||||||
{
|
|
||||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue(surfaceToUpload.GenerateMimeType(CoreConfiguration, _flickrConfiguration));
|
streamContent.Headers.ContentType = new MediaTypeHeaderValue(surfaceToUpload.GenerateMimeType(CoreConfiguration, _flickrConfiguration));
|
||||||
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
||||||
{
|
{
|
||||||
|
@ -239,7 +234,6 @@ namespace Greenshot.Addon.Flickr
|
||||||
where element.Name == "photoid"
|
where element.Name == "photoid"
|
||||||
select element.Value).FirstOrDefault();
|
select element.Value).FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Get Photo Info
|
// Get Photo Info
|
||||||
signedParameters = new Dictionary<string, object>
|
signedParameters = new Dictionary<string, object>
|
||||||
|
|
|
@ -103,12 +103,10 @@ namespace Greenshot.Addon.GooglePhotos
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this by caching
|
// TODO: Optimize this by caching
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "GooglePhotos.png"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "GooglePhotos.png");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
||||||
|
@ -145,12 +143,10 @@ namespace Greenshot.Addon.GooglePhotos
|
||||||
|
|
||||||
if (url != null && _googlePhotosConfiguration.AfterUploadLinkToClipBoard)
|
if (url != null && _googlePhotosConfiguration.AfterUploadLinkToClipBoard)
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(url);
|
clipboardAccessToken.SetAsUrl(url);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -191,14 +187,12 @@ namespace Greenshot.Addon.GooglePhotos
|
||||||
{
|
{
|
||||||
surface.WriteToStream(imageStream, CoreConfiguration, _googlePhotosConfiguration);
|
surface.WriteToStream(imageStream, CoreConfiguration, _googlePhotosConfiguration);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
using (var content = new StreamContent(imageStream))
|
using var content = new StreamContent(imageStream);
|
||||||
{
|
|
||||||
content.Headers.Add("Content-Type", surface.GenerateMimeType(CoreConfiguration, _googlePhotosConfiguration));
|
content.Headers.Add("Content-Type", surface.GenerateMimeType(CoreConfiguration, _googlePhotosConfiguration));
|
||||||
|
|
||||||
oAuthHttpBehaviour.MakeCurrent();
|
oAuthHttpBehaviour.MakeCurrent();
|
||||||
response = await uploadUri.PostAsync<string>(content, token).ConfigureAwait(true);
|
response = await uploadUri.PostAsync<string>(content, token).ConfigureAwait(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return ParseResponse(response);
|
return ParseResponse(response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,18 +104,14 @@ namespace Greenshot.Addon.Imgur
|
||||||
localBehaviour.UploadProgress = percent => Execute.OnUIThread(() => progress.Report((int)(percent * 100)));
|
localBehaviour.UploadProgress = percent => Execute.OnUIThread(() => progress.Report((int)(percent * 100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var imageStream = new MemoryStream())
|
using var imageStream = new MemoryStream();
|
||||||
{
|
|
||||||
surfaceToUpload.WriteToStream(imageStream, _coreConfiguration, _imgurConfiguration);
|
surfaceToUpload.WriteToStream(imageStream, _coreConfiguration, _imgurConfiguration);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
using (var content = new StreamContent(imageStream))
|
using var content = new StreamContent(imageStream);
|
||||||
{
|
|
||||||
content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(_coreConfiguration, _imgurConfiguration));
|
content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(_coreConfiguration, _imgurConfiguration));
|
||||||
localBehaviour.MakeCurrent();
|
localBehaviour.MakeCurrent();
|
||||||
return await uploadUri.PostAsync<ImgurImage>(content, token).ConfigureAwait(false);
|
return await uploadUri.PostAsync<ImgurImage>(content, token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Do the actual upload to Picasa
|
/// Do the actual upload to Picasa
|
||||||
|
@ -135,18 +131,14 @@ namespace Greenshot.Addon.Imgur
|
||||||
localBehaviour.UploadProgress = percent => Execute.OnUIThread(() => progress.Report((int) (percent * 100)));
|
localBehaviour.UploadProgress = percent => Execute.OnUIThread(() => progress.Report((int) (percent * 100)));
|
||||||
}
|
}
|
||||||
var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);
|
var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);
|
||||||
using (var imageStream = new MemoryStream())
|
using var imageStream = new MemoryStream();
|
||||||
{
|
|
||||||
surfaceToUpload.WriteToStream(imageStream, _coreConfiguration, _imgurConfiguration);
|
surfaceToUpload.WriteToStream(imageStream, _coreConfiguration, _imgurConfiguration);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
using (var content = new StreamContent(imageStream))
|
using var content = new StreamContent(imageStream);
|
||||||
{
|
|
||||||
content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(_coreConfiguration, _imgurConfiguration));
|
content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(_coreConfiguration, _imgurConfiguration));
|
||||||
oauthHttpBehaviour.MakeCurrent();
|
oauthHttpBehaviour.MakeCurrent();
|
||||||
return await uploadUri.PostAsync<ImgurImage>(content, token).ConfigureAwait(false);
|
return await uploadUri.PostAsync<ImgurImage>(content, token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -187,8 +179,7 @@ namespace Greenshot.Addon.Imgur
|
||||||
{
|
{
|
||||||
var creditsUri = new Uri($"{_imgurConfiguration.ApiUrl}/credits.json");
|
var creditsUri = new Uri($"{_imgurConfiguration.ApiUrl}/credits.json");
|
||||||
Behaviour.MakeCurrent();
|
Behaviour.MakeCurrent();
|
||||||
using (var client = HttpClientFactory.Create(creditsUri))
|
using var client = HttpClientFactory.Create(creditsUri);
|
||||||
{
|
|
||||||
var response = await client.GetAsync(creditsUri, token).ConfigureAwait(false);
|
var response = await client.GetAsync(creditsUri, token).ConfigureAwait(false);
|
||||||
await response.HandleErrorAsync().ConfigureAwait(false);
|
await response.HandleErrorAsync().ConfigureAwait(false);
|
||||||
var creditsJson = await response.GetAsAsync<dynamic>(token).ConfigureAwait(false);
|
var creditsJson = await response.GetAsAsync<dynamic>(token).ConfigureAwait(false);
|
||||||
|
@ -209,7 +200,6 @@ namespace Greenshot.Addon.Imgur
|
||||||
_imgurConfiguration.Credits = credits;
|
_imgurConfiguration.Credits = credits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve information on an imgur image
|
/// Retrieve information on an imgur image
|
||||||
|
@ -224,8 +214,7 @@ namespace Greenshot.Addon.Imgur
|
||||||
Log.Debug().WriteLine("Retrieving Imgur info for {0} with url {1}", id, imageUri);
|
Log.Debug().WriteLine("Retrieving Imgur info for {0} with url {1}", id, imageUri);
|
||||||
|
|
||||||
Behaviour.MakeCurrent();
|
Behaviour.MakeCurrent();
|
||||||
using (var client = HttpClientFactory.Create(imageUri))
|
using var client = HttpClientFactory.Create(imageUri);
|
||||||
{
|
|
||||||
var response = await client.GetAsync(imageUri, token).ConfigureAwait(false);
|
var response = await client.GetAsync(imageUri, token).ConfigureAwait(false);
|
||||||
// retrieving image data seems to throw a 403 (Unauthorized) if it has been deleted
|
// retrieving image data seems to throw a 403 (Unauthorized) if it has been deleted
|
||||||
if ((response.StatusCode == HttpStatusCode.NotFound) || (response.StatusCode == HttpStatusCode.Redirect) || (response.StatusCode == HttpStatusCode.Unauthorized))
|
if ((response.StatusCode == HttpStatusCode.NotFound) || (response.StatusCode == HttpStatusCode.Redirect) || (response.StatusCode == HttpStatusCode.Unauthorized))
|
||||||
|
@ -235,7 +224,6 @@ namespace Greenshot.Addon.Imgur
|
||||||
await response.HandleErrorAsync().ConfigureAwait(false);
|
await response.HandleErrorAsync().ConfigureAwait(false);
|
||||||
return await response.GetAsAsync<ImgurImage>(token).ConfigureAwait(false);
|
return await response.GetAsAsync<ImgurImage>(token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve the thumbnail of an imgur image
|
/// Retrieve the thumbnail of an imgur image
|
||||||
|
|
|
@ -83,11 +83,9 @@ namespace Greenshot.Addon.Imgur
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this, by caching
|
// TODO: Optimize this, by caching
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "Imgur.png"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "Imgur.png");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
||||||
|
@ -128,10 +126,11 @@ namespace Greenshot.Addon.Imgur
|
||||||
{
|
{
|
||||||
// Create thumbnail
|
// Create thumbnail
|
||||||
using (var tmpImage = surfaceToUpload.GetBitmapForExport())
|
using (var tmpImage = surfaceToUpload.GetBitmapForExport())
|
||||||
using (var thumbnail = tmpImage.CreateThumbnail(90, 90))
|
|
||||||
{
|
{
|
||||||
|
using var thumbnail = tmpImage.CreateThumbnail(90, 90);
|
||||||
imgurImage.Image = thumbnail;
|
imgurImage.Image = thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_imgurConfiguration.AnonymousAccess && _imgurConfiguration.TrackHistory)
|
if (_imgurConfiguration.AnonymousAccess && _imgurConfiguration.TrackHistory)
|
||||||
{
|
{
|
||||||
Log.Debug().WriteLine("Storing imgur upload for hash {0} and delete hash {1}", imgurImage.Data.Id, imgurImage.Data.Deletehash);
|
Log.Debug().WriteLine("Storing imgur upload for hash {0} and delete hash {1}", imgurImage.Data.Id, imgurImage.Data.Deletehash);
|
||||||
|
@ -159,12 +158,10 @@ namespace Greenshot.Addon.Imgur
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(uploadUrl.AbsoluteUri);
|
clipboardAccessToken.SetAsUrl(uploadUrl.AbsoluteUri);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error().WriteLine(ex, "Can't write to clipboard: ");
|
Log.Error().WriteLine(ex, "Can't write to clipboard: ");
|
||||||
|
|
|
@ -120,11 +120,9 @@ namespace Greenshot.Addon.Imgur.ViewModels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ShowHistory()
|
public void ShowHistory()
|
||||||
{
|
{
|
||||||
using (var imgurHistoryViewModel = ImgurHistoryViewModelFactory())
|
using var imgurHistoryViewModel = ImgurHistoryViewModelFactory();
|
||||||
{
|
|
||||||
WindowManager.ShowDialog(imgurHistoryViewModel.Value);
|
WindowManager.ShowDialog(imgurHistoryViewModel.Value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Can the credentials be reset?
|
/// Can the credentials be reset?
|
||||||
|
|
|
@ -177,12 +177,10 @@ namespace Greenshot.Addon.Imgur.ViewModels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CopyToClipboard()
|
public void CopyToClipboard()
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(SelectedImgur.Data.Link?.AbsoluteUri);
|
clipboardAccessToken.SetAsUrl(SelectedImgur.Data.Link?.AbsoluteUri);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used from the View
|
/// Used from the View
|
||||||
|
|
|
@ -392,7 +392,7 @@ namespace Greenshot.Addon.InternetExplorer
|
||||||
windowToCapture = InteropWindowQuery.GetForegroundWindow();
|
windowToCapture = InteropWindowQuery.GetForegroundWindow();
|
||||||
}
|
}
|
||||||
// Show backgroundform after retrieving the active window..
|
// Show backgroundform after retrieving the active window..
|
||||||
var backgroundForm = new BackgroundForm("Internet Explorer", "Please wait while the page in Internet Explorer is captured...");
|
using var backgroundForm = new BackgroundForm("Internet Explorer", "Please wait while the page in Internet Explorer is captured...");
|
||||||
backgroundForm.Show();
|
backgroundForm.Show();
|
||||||
//BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
|
//BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
|
||||||
try
|
try
|
||||||
|
@ -659,11 +659,9 @@ namespace Greenshot.Addon.InternetExplorer
|
||||||
// Loop over the frames and clear their source area so we don't see any artifacts
|
// Loop over the frames and clear their source area so we don't see any artifacts
|
||||||
foreach (var frameDocument in documentContainer.Frames)
|
foreach (var frameDocument in documentContainer.Frames)
|
||||||
{
|
{
|
||||||
using (var brush = new SolidBrush(clearColor))
|
using var brush = new SolidBrush(clearColor);
|
||||||
{
|
|
||||||
graphicsTarget.FillRectangle(brush, frameDocument.SourceRectangle);
|
graphicsTarget.FillRectangle(brush, frameDocument.SourceRectangle);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Loop over the frames and capture their content
|
// Loop over the frames and capture their content
|
||||||
foreach (var frameDocument in documentContainer.Frames)
|
foreach (var frameDocument in documentContainer.Frames)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Dapplo.Log;
|
|
||||||
using Dapplo.Windows.Desktop;
|
using Dapplo.Windows.Desktop;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
@ -31,8 +30,6 @@ namespace Greenshot.Addon.InternetExplorer {
|
||||||
/// Util code for Internet Explorer
|
/// Util code for Internet Explorer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class InternetExplorerHelper {
|
public class InternetExplorerHelper {
|
||||||
private static readonly LogSource Log = new LogSource();
|
|
||||||
|
|
||||||
// Internet explorer Registry key
|
// Internet explorer Registry key
|
||||||
private const string IeKey = @"Software\Microsoft\Internet Explorer";
|
private const string IeKey = @"Software\Microsoft\Internet Explorer";
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,6 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapplo.Jira" Version="0.9.2" />
|
<PackageReference Include="Dapplo.Jira" Version="0.9.2" />
|
||||||
<PackageReference Include="DynamicData" Version="6.13.13" />
|
<PackageReference Include="DynamicData" Version="6.14.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -91,7 +91,11 @@ namespace Greenshot.Addon.Jira
|
||||||
{
|
{
|
||||||
if (_jiraClient != null)
|
if (_jiraClient != null)
|
||||||
{
|
{
|
||||||
Task.Run(async () => await LogoutAsync()).Wait();
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await LogoutAsync();
|
||||||
|
_issueTypeBitmapCache.Dispose();
|
||||||
|
}).Wait();
|
||||||
}
|
}
|
||||||
FavIcon?.Dispose();
|
FavIcon?.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -251,14 +255,12 @@ namespace Greenshot.Addon.Jira
|
||||||
public async Task AttachAsync(string issueKey, ISurface surface, string filename = null, CancellationToken cancellationToken = default)
|
public async Task AttachAsync(string issueKey, ISurface surface, string filename = null, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
await CheckCredentialsAsync(cancellationToken).ConfigureAwait(true);
|
await CheckCredentialsAsync(cancellationToken).ConfigureAwait(true);
|
||||||
using (var memoryStream = new MemoryStream())
|
using var memoryStream = new MemoryStream();
|
||||||
{
|
|
||||||
surface.WriteToStream(memoryStream, _coreConfiguration, _jiraConfiguration);
|
surface.WriteToStream(memoryStream, _coreConfiguration, _jiraConfiguration);
|
||||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||||
var contentType = surface.GenerateMimeType(_coreConfiguration, _jiraConfiguration);
|
var contentType = surface.GenerateMimeType(_coreConfiguration, _jiraConfiguration);
|
||||||
await _jiraClient.Attachment.AttachAsync(issueKey, memoryStream, filename ?? surface.GenerateFilename(_coreConfiguration, _jiraConfiguration), contentType, cancellationToken).ConfigureAwait(false);
|
await _jiraClient.Attachment.AttachAsync(issueKey, memoryStream, filename ?? surface.GenerateFilename(_coreConfiguration, _jiraConfiguration), contentType, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a comment to the supplied issue
|
/// Add a comment to the supplied issue
|
||||||
|
|
|
@ -137,14 +137,10 @@ namespace Greenshot.Addon.Jira
|
||||||
}
|
}
|
||||||
if (displayIcon == null)
|
if (displayIcon == null)
|
||||||
{
|
{
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "jira.svgz"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "jira.svgz");
|
||||||
{
|
using var gzStream = new GZipStream(bitmapStream, CompressionMode.Decompress);
|
||||||
using (var gzStream = new GZipStream(bitmapStream, CompressionMode.Decompress))
|
|
||||||
{
|
|
||||||
displayIcon = SvgBitmap.FromStream(gzStream);
|
displayIcon = SvgBitmap.FromStream(gzStream);
|
||||||
}
|
|
||||||
//displayIcon = BitmapHelper.FromStream(bitmapStream);
|
//displayIcon = BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return displayIcon;
|
return displayIcon;
|
||||||
}
|
}
|
||||||
|
@ -195,8 +191,7 @@ namespace Greenshot.Addon.Jira
|
||||||
{
|
{
|
||||||
// TODO: set filename
|
// TODO: set filename
|
||||||
// _jiraViewModel.SetFilename(filename);
|
// _jiraViewModel.SetFilename(filename);
|
||||||
using (var jiraViewModel = _jiraViewModelFactory())
|
using var jiraViewModel = _jiraViewModelFactory();
|
||||||
{
|
|
||||||
if (_windowManager.ShowDialog(jiraViewModel.Value) == true)
|
if (_windowManager.ShowDialog(jiraViewModel.Value) == true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -229,7 +224,6 @@ namespace Greenshot.Addon.Jira
|
||||||
MessageBox.Show(_jiraLanguage.UploadFailure + " " + e.Message);
|
MessageBox.Show(_jiraLanguage.UploadFailure + " " + e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_exportNotification.NotifyOfExport(this, exportInformation, surface);
|
_exportNotification.NotifyOfExport(this, exportInformation, surface);
|
||||||
return exportInformation;
|
return exportInformation;
|
||||||
|
|
|
@ -53,18 +53,14 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
|
|
||||||
if (Image != null)
|
if (Image != null)
|
||||||
{
|
{
|
||||||
using (var brush = value != Color.Transparent ? new SolidBrush(value) : (Brush) new HatchBrush(HatchStyle.Percent50, Color.White, Color.Gray))
|
using var brush = value != Color.Transparent ? new SolidBrush(value) : (Brush) new HatchBrush(HatchStyle.Percent50, Color.White, Color.Gray);
|
||||||
{
|
using var graphics = Graphics.FromImage(Image);
|
||||||
using (var graphics = Graphics.FromImage(Image))
|
|
||||||
{
|
|
||||||
int verticalOffset = Image.Height / 3;
|
int verticalOffset = Image.Height / 3;
|
||||||
int horizontalOffset = (Image.Width / 3) / 2;
|
int horizontalOffset = (Image.Width / 3) / 2;
|
||||||
int width = Image.Width - (Image.Width / 3);
|
int width = Image.Width - (Image.Width / 3);
|
||||||
int height = (Image.Height / 3) / 2;
|
int height = (Image.Height / 3) / 2;
|
||||||
graphics.FillRectangle(brush, new Rectangle(horizontalOffset, verticalOffset, width, height));
|
graphics.FillRectangle(brush, new Rectangle(horizontalOffset, verticalOffset, width, height));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,8 +74,7 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
|
|
||||||
private void ColorButtonClick(object sender, EventArgs e)
|
private void ColorButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
using (var ownedColorDialog = _colorDialogFactory())
|
using var ownedColorDialog = _colorDialogFactory();
|
||||||
{
|
|
||||||
var colorDialog = ownedColorDialog.Value;
|
var colorDialog = ownedColorDialog.Value;
|
||||||
colorDialog.Color = SelectedColor;
|
colorDialog.Color = SelectedColor;
|
||||||
// Using the parent to make sure the dialog doesn't show on another window
|
// Using the parent to make sure the dialog doesn't show on another window
|
||||||
|
@ -97,4 +92,3 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -39,6 +39,7 @@ namespace Greenshot.Addon.LegacyEditor.Controls {
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
|
_toolTip.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,7 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
}
|
}
|
||||||
var graphics = e.Graphics;
|
var graphics = e.Graphics;
|
||||||
var dropDownRect = e.ArrowRectangle;
|
var dropDownRect = e.ArrowRectangle;
|
||||||
using (var brush = new SolidBrush(e.ArrowColor))
|
using var brush = new SolidBrush(e.ArrowColor);
|
||||||
{
|
|
||||||
int halfHeight = e.ArrowRectangle.Height / 2;
|
int halfHeight = e.ArrowRectangle.Height / 2;
|
||||||
int halfWidth = e.ArrowRectangle.Width / 2;
|
int halfWidth = e.ArrowRectangle.Width / 2;
|
||||||
var middle = new Point(dropDownRect.Left + halfWidth, dropDownRect.Top + halfHeight);
|
var middle = new Point(dropDownRect.Left + halfWidth, dropDownRect.Top + halfHeight);
|
||||||
|
@ -64,39 +63,30 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
int horizontalArrowStart = middle.X - halfWidth;
|
int horizontalArrowStart = middle.X - halfWidth;
|
||||||
int horizontalArrowEnd = middle.X + halfWidth;
|
int horizontalArrowEnd = middle.X + halfWidth;
|
||||||
|
|
||||||
switch (e.Direction)
|
arrow = e.Direction switch
|
||||||
|
{
|
||||||
|
ArrowDirection.Up => new[]
|
||||||
{
|
{
|
||||||
case ArrowDirection.Up:
|
|
||||||
|
|
||||||
arrow = new[] {
|
|
||||||
new Point(horizontalArrowStart, verticalArrowEnd),
|
new Point(horizontalArrowStart, verticalArrowEnd),
|
||||||
new Point(horizontalArrowEnd, verticalArrowEnd),
|
new Point(horizontalArrowEnd, verticalArrowEnd), new Point(middle.X, verticalArrowStart)
|
||||||
new Point(middle.X, verticalArrowStart)};
|
},
|
||||||
|
ArrowDirection.Left => new[]
|
||||||
break;
|
{
|
||||||
case ArrowDirection.Left:
|
|
||||||
arrow = new[] {
|
|
||||||
new Point(horizontalArrowEnd, verticalArrowStart),
|
new Point(horizontalArrowEnd, verticalArrowStart),
|
||||||
new Point(horizontalArrowEnd, verticalArrowEnd),
|
new Point(horizontalArrowEnd, verticalArrowEnd), new Point(horizontalArrowStart, middle.Y)
|
||||||
new Point(horizontalArrowStart, middle.Y)};
|
},
|
||||||
|
ArrowDirection.Right => new[]
|
||||||
break;
|
{
|
||||||
case ArrowDirection.Right:
|
|
||||||
arrow = new[] {
|
|
||||||
new Point(horizontalArrowStart, verticalArrowStart),
|
new Point(horizontalArrowStart, verticalArrowStart),
|
||||||
new Point(horizontalArrowStart, verticalArrowEnd),
|
new Point(horizontalArrowStart, verticalArrowEnd), new Point(horizontalArrowEnd, middle.Y)
|
||||||
new Point(horizontalArrowEnd, middle.Y)};
|
},
|
||||||
|
_ => new[]
|
||||||
break;
|
{
|
||||||
default:
|
|
||||||
arrow = new[] {
|
|
||||||
new Point(horizontalArrowStart, verticalArrowStart),
|
new Point(horizontalArrowStart, verticalArrowStart),
|
||||||
new Point(horizontalArrowEnd, verticalArrowStart),
|
new Point(horizontalArrowEnd, verticalArrowStart), new Point(middle.X, verticalArrowEnd)
|
||||||
new Point(middle.X, verticalArrowEnd) };
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
graphics.FillPolygon(brush, arrow);
|
graphics.FillPolygon(brush, arrow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -117,16 +117,11 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
private void DrawText(Graphics graphics, FontFamily fontFamily, FontStyle fontStyle, Rectangle bounds, string text)
|
private void DrawText(Graphics graphics, FontFamily fontFamily, FontStyle fontStyle, Rectangle bounds, string text)
|
||||||
{
|
{
|
||||||
using (var font = new Font(fontFamily, Font.Size + 5, fontStyle, GraphicsUnit.Pixel))
|
using var font = new Font(fontFamily, Font.Size + 5, fontStyle, GraphicsUnit.Pixel);
|
||||||
{
|
|
||||||
// Make sure the text is visible by centering it in the line
|
// Make sure the text is visible by centering it in the line
|
||||||
using (var stringFormat = new StringFormat())
|
using var stringFormat = new StringFormat {LineAlignment = StringAlignment.Center};
|
||||||
{
|
|
||||||
stringFormat.LineAlignment = StringAlignment.Center;
|
|
||||||
graphics.DrawString(text, font, Brushes.Black, bounds, stringFormat);
|
graphics.DrawString(text, font, Brushes.Black, bounds, stringFormat);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void BindableToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
private void BindableToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
{
|
{
|
||||||
private const int VkEsc = 27;
|
private const int VkEsc = 27;
|
||||||
private readonly IBitmapWithNativeSupport _image;
|
private readonly IBitmapWithNativeSupport _image;
|
||||||
private Cursor _cursor;
|
private readonly Cursor _cursor;
|
||||||
private bool _dragging;
|
private bool _dragging;
|
||||||
private MovableShowColorForm _movableShowColorForm;
|
private MovableShowColorForm _movableShowColorForm;
|
||||||
|
|
||||||
|
@ -88,15 +88,13 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
/// <returns>Cursor</returns>
|
/// <returns>Cursor</returns>
|
||||||
private static Cursor CreateCursor(IBitmapWithNativeSupport bitmap, int hotspotX, int hotspotY)
|
private static Cursor CreateCursor(IBitmapWithNativeSupport bitmap, int hotspotX, int hotspotY)
|
||||||
{
|
{
|
||||||
using (var iconHandle = new SafeIconHandle(bitmap.NativeBitmap.GetHicon()))
|
using var iconHandle = new SafeIconHandle(bitmap.NativeBitmap.GetHicon());
|
||||||
{
|
|
||||||
NativeIconMethods.GetIconInfo(iconHandle, out var iconInfo);
|
NativeIconMethods.GetIconInfo(iconHandle, out var iconInfo);
|
||||||
iconInfo.Hotspot = new NativePoint(hotspotX, hotspotY);
|
iconInfo.Hotspot = new NativePoint(hotspotX, hotspotY);
|
||||||
iconInfo.IsIcon = false;
|
iconInfo.IsIcon = false;
|
||||||
var icon = NativeIconMethods.CreateIconIndirect(ref iconInfo);
|
var icon = NativeIconMethods.CreateIconIndirect(ref iconInfo);
|
||||||
return new Cursor(icon);
|
return new Cursor(icon);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This Dispose is called from the Dispose and the Destructor.
|
/// This Dispose is called from the Dispose and the Destructor.
|
||||||
|
@ -105,15 +103,12 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
|
||||||
if (_cursor != null)
|
|
||||||
{
|
{
|
||||||
_cursor.Dispose();
|
_cursor.Dispose();
|
||||||
}
|
|
||||||
_movableShowColorForm?.Dispose();
|
_movableShowColorForm?.Dispose();
|
||||||
|
_image.Dispose();
|
||||||
}
|
}
|
||||||
_movableShowColorForm = null;
|
_movableShowColorForm = null;
|
||||||
_cursor = null;
|
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,13 +61,11 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
|
|
||||||
if (Image != null)
|
if (Image != null)
|
||||||
{
|
{
|
||||||
using (var graphics = Graphics.FromImage(Image))
|
using var graphics = Graphics.FromImage(Image);
|
||||||
{
|
|
||||||
int quarterSize = Image.Height / 4;
|
int quarterSize = Image.Height / 4;
|
||||||
var colorArea = new Rectangle(0, Image.Height - quarterSize, Image.Width, quarterSize);
|
var colorArea = new Rectangle(0, Image.Height - quarterSize, Image.Width, quarterSize);
|
||||||
graphics.FillRectangle(brush, colorArea);
|
graphics.FillRectangle(brush, colorArea);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// cleanup GDI Object
|
// cleanup GDI Object
|
||||||
brush.Dispose();
|
brush.Dispose();
|
||||||
|
@ -84,7 +82,7 @@ namespace Greenshot.Addon.LegacyEditor.Controls
|
||||||
|
|
||||||
private void ColorButtonClick(object sender, EventArgs e)
|
private void ColorButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var colorDialog = new ColorDialog(_editorConfiguration, _greenshotLanguage)
|
using var colorDialog = new ColorDialog(_editorConfiguration, _greenshotLanguage)
|
||||||
{
|
{
|
||||||
Color = SelectedColor
|
Color = SelectedColor
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,11 +99,8 @@ namespace Greenshot.Addon.LegacyEditor.Drawing.Adorners
|
||||||
var targetGraphics = paintEventArgs.Graphics;
|
var targetGraphics = paintEventArgs.Graphics;
|
||||||
|
|
||||||
var bounds = Bounds;
|
var bounds = Bounds;
|
||||||
using (var brush = new SolidBrush(_color))
|
using var brush = new SolidBrush(_color);
|
||||||
{
|
|
||||||
targetGraphics.FillRectangle(brush, bounds.X, bounds.Y, bounds.Width, bounds.Height);
|
targetGraphics.FillRectangle(brush, bounds.X, bounds.Y, bounds.Width, bounds.Height);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -57,22 +57,15 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
return NativeRect.Empty;
|
return NativeRect.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var pen = new Pen(Color.White))
|
using var pen = new Pen(Color.White) {Width = lineThickness};
|
||||||
{
|
|
||||||
pen.Width = lineThickness;
|
|
||||||
SetArrowHeads((ArrowHeadCombination) GetFieldValue(FieldTypes.ARROWHEADS), pen);
|
SetArrowHeads((ArrowHeadCombination) GetFieldValue(FieldTypes.ARROWHEADS), pen);
|
||||||
using (var path = new GraphicsPath())
|
using var path = new GraphicsPath();
|
||||||
{
|
|
||||||
path.AddLine(Left, Top, Left + Width, Top + Height);
|
path.AddLine(Left, Top, Left + Width, Top + Height);
|
||||||
using (var matrix = new Matrix())
|
using var matrix = new Matrix();
|
||||||
{
|
|
||||||
NativeRectFloat drawingBounds = path.GetBounds(matrix, pen);
|
NativeRectFloat drawingBounds = path.GetBounds(matrix, pen);
|
||||||
return drawingBounds.Inflate(2, 2).Round();
|
return drawingBounds.Inflate(2, 2).Round();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Do not use the base, just override so we have our own defaults
|
/// Do not use the base, just override so we have our own defaults
|
||||||
|
@ -110,8 +103,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var currentStep = 1;
|
var currentStep = 1;
|
||||||
while (currentStep <= steps)
|
while (currentStep <= steps)
|
||||||
{
|
{
|
||||||
using (var shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness))
|
using var shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness);
|
||||||
{
|
|
||||||
SetArrowHeads(heads, shadowCapPen);
|
SetArrowHeads(heads, shadowCapPen);
|
||||||
|
|
||||||
graphics.DrawLine(shadowCapPen,
|
graphics.DrawLine(shadowCapPen,
|
||||||
|
@ -124,15 +116,13 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
alpha = alpha - basealpha / steps;
|
alpha = alpha - basealpha / steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
SetArrowHeads(heads, pen);
|
SetArrowHeads(heads, pen);
|
||||||
graphics.DrawLine(pen, Left, Top, Left + Width, Top + Height);
|
graphics.DrawLine(pen, Left, Top, Left + Width, Top + Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void SetArrowHeads(ArrowHeadCombination heads, Pen pen)
|
private void SetArrowHeads(ArrowHeadCombination heads, Pen pen)
|
||||||
{
|
{
|
||||||
|
@ -151,17 +141,12 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS) + 10;
|
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS) + 10;
|
||||||
if (lineThickness > 0)
|
if (lineThickness > 0)
|
||||||
{
|
{
|
||||||
using (var pen = new Pen(Color.White))
|
using var pen = new Pen(Color.White) {Width = lineThickness};
|
||||||
{
|
|
||||||
pen.Width = lineThickness;
|
|
||||||
SetArrowHeads((ArrowHeadCombination) GetFieldValue(FieldTypes.ARROWHEADS), pen);
|
SetArrowHeads((ArrowHeadCombination) GetFieldValue(FieldTypes.ARROWHEADS), pen);
|
||||||
using (var path = new GraphicsPath())
|
using var path = new GraphicsPath();
|
||||||
{
|
|
||||||
path.AddLine(Left, Top, Left + Width, Top + Height);
|
path.AddLine(Left, Top, Left + Width, Top + Height);
|
||||||
return path.IsOutlineVisible(x, y, pen);
|
return path.IsOutlineVisible(x, y, pen);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,14 +109,12 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
Log.Debug().WriteLine("Rotating element with {0} degrees.", rotateAngle);
|
Log.Debug().WriteLine("Rotating element with {0} degrees.", rotateAngle);
|
||||||
DisposeShadow();
|
DisposeShadow();
|
||||||
using (var tmpMatrix = new Matrix())
|
using var tmpMatrix = new Matrix();
|
||||||
{
|
|
||||||
using (_bitmap)
|
using (_bitmap)
|
||||||
{
|
{
|
||||||
_bitmap = _bitmap.ApplyEffect(new RotateEffect(rotateAngle), tmpMatrix);
|
_bitmap = _bitmap.ApplyEffect(new RotateEffect(rotateAngle), tmpMatrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
base.Transform(matrix);
|
base.Transform(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,12 +224,10 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
if (shadow && _shadowBitmap == null)
|
if (shadow && _shadowBitmap == null)
|
||||||
{
|
{
|
||||||
using (var matrix = new Matrix())
|
using var matrix = new Matrix();
|
||||||
{
|
|
||||||
_shadowBitmap = _bitmap.ApplyEffect(new DropShadowEffect(), matrix);
|
_shadowBitmap = _bitmap.ApplyEffect(new DropShadowEffect(), matrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draw the actual container to the graphics object
|
/// Draw the actual container to the graphics object
|
||||||
|
|
|
@ -79,8 +79,8 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using (Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100)))
|
|
||||||
{
|
using Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100));
|
||||||
var cropRectangle = new NativeRect(Left, Top, Width, Height).Normalize();
|
var cropRectangle = new NativeRect(Left, Top, Width, Height).Normalize();
|
||||||
var selectionRect = new NativeRect(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);
|
var selectionRect = new NativeRect(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);
|
||||||
|
|
||||||
|
@ -98,4 +98,3 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -75,12 +75,11 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using (var fileCursor = new Cursor(filename))
|
|
||||||
{
|
using var fileCursor = new Cursor(filename);
|
||||||
Cursor = fileCursor;
|
Cursor = fileCursor;
|
||||||
Log.Debug().WriteLine("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
Log.Debug().WriteLine("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDeserialized(StreamingContext streamingContext)
|
protected override void OnDeserialized(StreamingContext streamingContext)
|
||||||
{
|
{
|
||||||
|
|
|
@ -603,13 +603,13 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
|
|
||||||
protected void DrawSelectionBorder(Graphics g, NativeRect rect)
|
protected void DrawSelectionBorder(Graphics g, NativeRect rect)
|
||||||
{
|
{
|
||||||
using (var pen = new Pen(Color.MediumSeaGreen))
|
using var pen = new Pen(Color.MediumSeaGreen)
|
||||||
{
|
{
|
||||||
pen.DashPattern = new float[] {1, 2};
|
DashPattern = new float[] {1, 2},
|
||||||
pen.Width = 1;
|
Width = 1
|
||||||
|
};
|
||||||
g.DrawRectangle(pen, rect);
|
g.DrawRectangle(pen, rect);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void ResizeTo(int width, int height)
|
public void ResizeTo(int width, int height)
|
||||||
|
|
|
@ -83,32 +83,28 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var currentStep = lineVisible ? 1 : 0;
|
var currentStep = lineVisible ? 1 : 0;
|
||||||
while (currentStep <= steps)
|
while (currentStep <= steps)
|
||||||
{
|
{
|
||||||
using (var shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100)))
|
using var shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))
|
||||||
{
|
{
|
||||||
shadowPen.Width = lineVisible ? lineThickness : 1;
|
Width = lineVisible ? lineThickness : 1
|
||||||
|
};
|
||||||
var shadowRect = new NativeRect(rect.Left + currentStep, rect.Top + currentStep, rect.Width, rect.Height).Normalize();
|
var shadowRect = new NativeRect(rect.Left + currentStep, rect.Top + currentStep, rect.Width, rect.Height).Normalize();
|
||||||
graphics.DrawEllipse(shadowPen, shadowRect);
|
graphics.DrawEllipse(shadowPen, shadowRect);
|
||||||
currentStep++;
|
currentStep++;
|
||||||
alpha = alpha - basealpha / steps;
|
alpha = alpha - basealpha / steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//draw the original shape
|
//draw the original shape
|
||||||
if (Colors.IsVisible(fillColor))
|
if (Colors.IsVisible(fillColor))
|
||||||
{
|
{
|
||||||
using (Brush brush = new SolidBrush(fillColor))
|
using Brush brush = new SolidBrush(fillColor);
|
||||||
{
|
|
||||||
graphics.FillEllipse(brush, rect);
|
graphics.FillEllipse(brush, rect);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (lineVisible)
|
if (lineVisible)
|
||||||
{
|
{
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
graphics.DrawEllipse(pen, rect);
|
graphics.DrawEllipse(pen, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Contains(int x, int y)
|
public override bool Contains(int x, int y)
|
||||||
{
|
{
|
||||||
|
@ -152,15 +148,11 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
// check the rest of the lines
|
// check the rest of the lines
|
||||||
if (lineThickness > 0)
|
if (lineThickness > 0)
|
||||||
{
|
{
|
||||||
using (var pen = new Pen(Color.White, lineThickness))
|
using var pen = new Pen(Color.White, lineThickness);
|
||||||
{
|
using var path = new GraphicsPath();
|
||||||
using (var path = new GraphicsPath())
|
|
||||||
{
|
|
||||||
path.AddEllipse(rect);
|
path.AddEllipse(rect);
|
||||||
return path.IsOutlineVisible(x, y, pen);
|
return path.IsOutlineVisible(x, y, pen);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,24 +86,20 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var currentStep = lineVisible ? 1 : 0;
|
var currentStep = lineVisible ? 1 : 0;
|
||||||
while (currentStep <= steps)
|
while (currentStep <= steps)
|
||||||
{
|
{
|
||||||
using (var shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness))
|
using var shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness);
|
||||||
{
|
|
||||||
var shadowRect = new NativeRect(Left + currentStep, Top + currentStep, Width, Height).Normalize();
|
var shadowRect = new NativeRect(Left + currentStep, Top + currentStep, Width, Height).Normalize();
|
||||||
graphics.DrawRectangle(shadowPen, shadowRect);
|
graphics.DrawRectangle(shadowPen, shadowRect);
|
||||||
currentStep++;
|
currentStep++;
|
||||||
alpha = alpha - baseAlpha / steps;
|
alpha = alpha - baseAlpha / steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
var rect = new NativeRect(Left, Top, Width, Height).Normalize();
|
var rect = new NativeRect(Left, Top, Width, Height).Normalize();
|
||||||
if (lineThickness > 0)
|
if (lineThickness > 0)
|
||||||
{
|
{
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
graphics.DrawRectangle(pen, rect);
|
graphics.DrawRectangle(pen, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -57,8 +57,8 @@ namespace Greenshot.Addon.LegacyEditor.Drawing.Filters
|
||||||
{
|
{
|
||||||
pixelSize = rect.Height;
|
pixelSize = rect.Height;
|
||||||
}
|
}
|
||||||
using (var dest = FastBitmapFactory.CreateCloneOf(applyBitmap, area: rect))
|
|
||||||
{
|
using var dest = FastBitmapFactory.CreateCloneOf(applyBitmap, area: rect);
|
||||||
using (var src = FastBitmapFactory.Create(applyBitmap, rect))
|
using (var src = FastBitmapFactory.Create(applyBitmap, rect))
|
||||||
{
|
{
|
||||||
var halbPixelSize = pixelSize / 2;
|
var halbPixelSize = pixelSize / 2;
|
||||||
|
@ -112,4 +112,3 @@ namespace Greenshot.Addon.LegacyEditor.Drawing.Filters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -186,8 +186,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
|
|
||||||
int lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
int lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
||||||
var lineColor = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
|
var lineColor = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
|
||||||
using (var pen = new Pen(lineColor)) {
|
using var pen = new Pen(lineColor) {Width = lineThickness};
|
||||||
pen.Width = lineThickness;
|
|
||||||
if (!(pen.Width > 0))
|
if (!(pen.Width > 0))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -210,7 +209,6 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
// Move back, otherwise everything is shifted
|
// Move back, otherwise everything is shifted
|
||||||
graphics.TranslateTransform(-Left,-Top);
|
graphics.TranslateTransform(-Left,-Top);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draw a selectionborder around the freehand path
|
/// Draw a selectionborder around the freehand path
|
||||||
|
@ -218,9 +216,10 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
/// <param name="graphics">Graphics</param>
|
/// <param name="graphics">Graphics</param>
|
||||||
/// <param name="linePen">Pen</param>
|
/// <param name="linePen">Pen</param>
|
||||||
/// <param name="path">GraphicsPath</param>
|
/// <param name="path">GraphicsPath</param>
|
||||||
protected static void DrawSelectionBorder(Graphics graphics, Pen linePen, GraphicsPath path) {
|
protected static void DrawSelectionBorder(Graphics graphics, Pen linePen, GraphicsPath path)
|
||||||
using (var selectionPen = (Pen) linePen.Clone()) {
|
{
|
||||||
using (var selectionPath = (GraphicsPath)path.Clone()) {
|
using var selectionPen = (Pen) linePen.Clone();
|
||||||
|
using var selectionPath = (GraphicsPath)path.Clone();
|
||||||
selectionPen.Width += 5;
|
selectionPen.Width += 5;
|
||||||
selectionPen.Color = Color.FromArgb(120, Color.LightSeaGreen);
|
selectionPen.Color = Color.FromArgb(120, Color.LightSeaGreen);
|
||||||
graphics.DrawPath(selectionPen, selectionPath);
|
graphics.DrawPath(selectionPen, selectionPath);
|
||||||
|
@ -230,8 +229,6 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
selectionPen.Width = 1;
|
selectionPen.Width = 1;
|
||||||
graphics.DrawPath(selectionPen, selectionPath);
|
graphics.DrawPath(selectionPen, selectionPath);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the bounds in which we have something drawn, plus safety margin, these are not the normal bounds...
|
/// Get the bounds in which we have something drawn, plus safety margin, these are not the normal bounds...
|
||||||
|
@ -276,12 +273,10 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
bool returnValue = base.ClickableAt(x, y);
|
bool returnValue = base.ClickableAt(x, y);
|
||||||
if (returnValue) {
|
if (returnValue) {
|
||||||
int lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
int lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
||||||
using (var pen = new Pen(Color.White)) {
|
using var pen = new Pen(Color.White) {Width = lineThickness + 10};
|
||||||
pen.Width = lineThickness + 10;
|
|
||||||
lock (_freehandPathLock)
|
lock (_freehandPathLock)
|
||||||
{
|
{
|
||||||
returnValue = _freehandPath.IsOutlineVisible(x - Left, y - Top, pen);
|
returnValue = _freehandPath.IsOutlineVisible(x - Left, y - Top, pen);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
|
|
|
@ -69,12 +69,11 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using (var fileIcon = new Icon(filename))
|
|
||||||
{
|
using var fileIcon = new Icon(filename);
|
||||||
Icon = fileIcon;
|
Icon = fileIcon;
|
||||||
Log.Debug().WriteLine("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
Log.Debug().WriteLine("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDeserialized(StreamingContext streamingContext)
|
protected override void OnDeserialized(StreamingContext streamingContext)
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,8 +92,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var currentStep = 1;
|
var currentStep = 1;
|
||||||
while (currentStep <= steps)
|
while (currentStep <= steps)
|
||||||
{
|
{
|
||||||
using (var shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness))
|
using var shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness);
|
||||||
{
|
|
||||||
graphics.DrawLine(shadowCapPen,
|
graphics.DrawLine(shadowCapPen,
|
||||||
Left + currentStep,
|
Left + currentStep,
|
||||||
Top + currentStep,
|
Top + currentStep,
|
||||||
|
@ -104,16 +103,13 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
#pragma warning disable IDE0054 // Use compound assignment
|
#pragma warning disable IDE0054 // Use compound assignment
|
||||||
alpha = alpha - basealpha / steps;
|
alpha = alpha - basealpha / steps;
|
||||||
#pragma warning restore IDE0054 // Use compound assignment
|
#pragma warning restore IDE0054 // Use compound assignment
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
graphics.DrawLine(pen, Left, Top, Left + Width, Top + Height);
|
graphics.DrawLine(pen, Left, Top, Left + Width, Top + Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool ClickableAt(int x, int y)
|
public override bool ClickableAt(int x, int y)
|
||||||
|
@ -121,16 +117,11 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS) + 5;
|
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS) + 5;
|
||||||
if (lineThickness > 0)
|
if (lineThickness > 0)
|
||||||
{
|
{
|
||||||
using (var pen = new Pen(Color.White))
|
using var pen = new Pen(Color.White) {Width = lineThickness};
|
||||||
{
|
using var path = new GraphicsPath();
|
||||||
pen.Width = lineThickness;
|
|
||||||
using (var path = new GraphicsPath())
|
|
||||||
{
|
|
||||||
path.AddLine(Left, Top, Left + Width, Top + Height);
|
path.AddLine(Left, Top, Left + Width, Top + Height);
|
||||||
return path.IsOutlineVisible(x, y, pen);
|
return path.IsOutlineVisible(x, y, pen);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,9 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
int alpha = basealpha;
|
int alpha = basealpha;
|
||||||
int steps = 5;
|
int steps = 5;
|
||||||
int currentStep = lineVisible ? 1 : 0;
|
int currentStep = lineVisible ? 1 : 0;
|
||||||
while (currentStep <= steps) {
|
while (currentStep <= steps)
|
||||||
using (var shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))) {
|
{
|
||||||
shadowPen.Width = lineVisible ? lineThickness : 1;
|
using var shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100)) {Width = lineVisible ? lineThickness : 1};
|
||||||
var shadowRect = new NativeRect(
|
var shadowRect = new NativeRect(
|
||||||
rect.Left + currentStep,
|
rect.Left + currentStep,
|
||||||
rect.Top + currentStep,
|
rect.Top + currentStep,
|
||||||
|
@ -107,21 +107,20 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
alpha = alpha - basealpha / steps;
|
alpha = alpha - basealpha / steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (Colors.IsVisible(fillColor)) {
|
if (Colors.IsVisible(fillColor))
|
||||||
using (Brush brush = new SolidBrush(fillColor)) {
|
{
|
||||||
|
using Brush brush = new SolidBrush(fillColor);
|
||||||
graphics.FillRectangle(brush, rect);
|
graphics.FillRectangle(brush, rect);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
graphics.SmoothingMode = SmoothingMode.HighSpeed;
|
graphics.SmoothingMode = SmoothingMode.HighSpeed;
|
||||||
if (lineVisible) {
|
if (lineVisible)
|
||||||
using (var pen = new Pen(lineColor, lineThickness)) {
|
{
|
||||||
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
graphics.DrawRectangle(pen, rect);
|
graphics.DrawRectangle(pen, rect);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public override bool ClickableAt(int x, int y) {
|
public override bool ClickableAt(int x, int y) {
|
||||||
|
@ -143,14 +142,13 @@ namespace Greenshot.Addon.LegacyEditor.Drawing {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the rest of the lines
|
// check the rest of the lines
|
||||||
if (lineThickness > 0) {
|
if (lineThickness > 0)
|
||||||
using (var pen = new Pen(Color.White, lineThickness)) {
|
{
|
||||||
using (var path = new GraphicsPath()) {
|
using var pen = new Pen(Color.White, lineThickness);
|
||||||
|
using var path = new GraphicsPath();
|
||||||
path.AddRectangle(rect);
|
path.AddRectangle(rect);
|
||||||
return path.IsOutlineVisible(x, y, pen);
|
return path.IsOutlineVisible(x, y, pen);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,18 +55,14 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
||||||
var lineColor = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
|
var lineColor = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
|
||||||
var shadow = GetFieldValueAsBool(FieldTypes.SHADOW);
|
var shadow = GetFieldValueAsBool(FieldTypes.SHADOW);
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
var inflateValue = lineThickness + 2 + (shadow ? 6 : 0);
|
var inflateValue = lineThickness + 2 + (shadow ? 6 : 0);
|
||||||
using (var tailPath = CreateTail())
|
using var tailPath = CreateTail();
|
||||||
{
|
|
||||||
NativeRectFloat tailBounds = tailPath.GetBounds(new Matrix(), pen);
|
NativeRectFloat tailBounds = tailPath.GetBounds(new Matrix(), pen);
|
||||||
var bounds = new NativeRect(Left, Top, Width, Height).Normalize();
|
var bounds = new NativeRect(Left, Top, Width, Height).Normalize();
|
||||||
|
|
||||||
return tailBounds.Round().Union(bounds).Inflate(inflateValue, inflateValue);
|
return tailBounds.Round().Union(bounds).Inflate(inflateValue, inflateValue);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return NativeRect.Empty;
|
return NativeRect.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,10 +233,9 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var alpha = basealpha;
|
var alpha = basealpha;
|
||||||
const int steps = 5;
|
const int steps = 5;
|
||||||
var currentStep = lineVisible ? 1 : 0;
|
var currentStep = lineVisible ? 1 : 0;
|
||||||
using (var shadowMatrix = new Matrix())
|
using var shadowMatrix = new Matrix();
|
||||||
using (var bubbleClone = (GraphicsPath) bubble.Clone())
|
using var bubbleClone = (GraphicsPath) bubble.Clone();
|
||||||
using (var tailClone = (GraphicsPath) tail.Clone())
|
using var tailClone = (GraphicsPath) tail.Clone();
|
||||||
{
|
|
||||||
shadowMatrix.Translate(1, 1);
|
shadowMatrix.Translate(1, 1);
|
||||||
while (currentStep <= steps)
|
while (currentStep <= steps)
|
||||||
{
|
{
|
||||||
|
@ -256,18 +251,15 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
alpha = alpha - basealpha / steps;
|
alpha = alpha - basealpha / steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var state = graphics.Save();
|
var state = graphics.Save();
|
||||||
// draw the tail border where the bubble is not visible
|
// draw the tail border where the bubble is not visible
|
||||||
using (var clipRegion = new Region(bubble))
|
using (var clipRegion = new Region(bubble))
|
||||||
{
|
{
|
||||||
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
graphics.DrawPath(pen, tail);
|
graphics.DrawPath(pen, tail);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
graphics.Restore(state);
|
graphics.Restore(state);
|
||||||
|
|
||||||
if (Colors.IsVisible(fillColor))
|
if (Colors.IsVisible(fillColor))
|
||||||
|
@ -289,12 +281,10 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
using (var clipRegion = new Region(tail))
|
using (var clipRegion = new Region(tail))
|
||||||
{
|
{
|
||||||
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
graphics.SetClip(clipRegion, CombineMode.Exclude);
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
//pen.EndCap = pen.StartCap = LineCap.Round;
|
//pen.EndCap = pen.StartCap = LineCap.Round;
|
||||||
graphics.DrawPath(pen, bubble);
|
graphics.DrawPath(pen, bubble);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
graphics.Restore(state);
|
graphics.Restore(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,8 +318,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
var lineThickness = GetFieldValueAsInt(FieldTypes.LINE_THICKNESS);
|
||||||
var lineColor = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
|
var lineColor = GetFieldValueAsColor(FieldTypes.LINE_COLOR);
|
||||||
using (var pen = new Pen(lineColor, lineThickness))
|
using var pen = new Pen(lineColor, lineThickness);
|
||||||
{
|
|
||||||
using (var bubblePath = CreateBubble(lineThickness))
|
using (var bubblePath = CreateBubble(lineThickness))
|
||||||
{
|
{
|
||||||
bubblePath.Widen(pen);
|
bubblePath.Widen(pen);
|
||||||
|
@ -338,16 +327,14 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using (var tailPath = CreateTail())
|
|
||||||
{
|
using var tailPath = CreateTail();
|
||||||
tailPath.Widen(pen);
|
tailPath.Widen(pen);
|
||||||
if (tailPath.IsVisible(clickedPoint))
|
if (tailPath.IsVisible(clickedPoint))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,14 +195,11 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
EllipseContainer.DrawEllipse(rect, graphics, rm, 0, Color.Transparent, fillColor, false);
|
EllipseContainer.DrawEllipse(rect, graphics, rm, 0, Color.Transparent, fillColor, false);
|
||||||
}
|
}
|
||||||
using (var fam = new FontFamily(FontFamily.GenericSansSerif.Name))
|
|
||||||
{
|
using var fam = new FontFamily(FontFamily.GenericSansSerif.Name);
|
||||||
using (var font = new Font(fam, _fontSize, FontStyle.Bold, GraphicsUnit.Pixel))
|
using var font = new Font(fam, _fontSize, FontStyle.Bold, GraphicsUnit.Pixel);
|
||||||
{
|
|
||||||
TextContainer.DrawText(graphics, rect, 0, lineColor, false, _stringFormat, text, font);
|
TextContainer.DrawText(graphics, rect, 0, lineColor, false, _stringFormat, text, font);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool ClickableAt(int x, int y)
|
public override bool ClickableAt(int x, int y)
|
||||||
{
|
{
|
||||||
|
|
|
@ -257,6 +257,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
||||||
/// <param name="editorConfiguration">IEditorConfiguration</param>
|
/// <param name="editorConfiguration">IEditorConfiguration</param>
|
||||||
|
/// <param name="editorLanguage">IEditorLanguage</param>
|
||||||
/// <param name="newBitmap">IBitmapWithNativeSupport</param>
|
/// <param name="newBitmap">IBitmapWithNativeSupport</param>
|
||||||
public Surface(ICoreConfiguration coreConfiguration, IEditorConfiguration editorConfiguration, IEditorLanguage editorLanguage, IBitmapWithNativeSupport newBitmap) : this(coreConfiguration, editorConfiguration, editorLanguage)
|
public Surface(ICoreConfiguration coreConfiguration, IEditorConfiguration editorConfiguration, IEditorLanguage editorLanguage, IBitmapWithNativeSupport newBitmap) : this(coreConfiguration, editorConfiguration, editorLanguage)
|
||||||
{
|
{
|
||||||
|
@ -563,7 +564,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
/// <param name="effect"></param>
|
/// <param name="effect"></param>
|
||||||
public void ApplyBitmapEffect(IEffect effect)
|
public void ApplyBitmapEffect(IEffect effect)
|
||||||
{
|
{
|
||||||
var backgroundForm = new BackgroundForm("Effect", "Please wait");
|
using var backgroundForm = new BackgroundForm("Effect", "Please wait");
|
||||||
backgroundForm.Show();
|
backgroundForm.Show();
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
try
|
try
|
||||||
|
@ -1079,6 +1080,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
// TODO: Check if we need to dispose _cursorContainer
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
Count--;
|
Count--;
|
||||||
|
@ -2035,15 +2037,13 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
var uri = new Uri(possibleUrl);
|
var uri = new Uri(possibleUrl);
|
||||||
|
|
||||||
using (var image = uri.GetAsAsync<Bitmap>().Result)
|
using var image = uri.GetAsAsync<Bitmap>().Result;
|
||||||
{
|
|
||||||
if (image != null)
|
if (image != null)
|
||||||
{
|
{
|
||||||
AddImageContainer(BitmapWrapper.FromBitmap(image), mouse.X, mouse.Y);
|
AddImageContainer(BitmapWrapper.FromBitmap(image), mouse.X, mouse.Y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -2054,8 +2054,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
var uri = new Uri(possibleUrl);
|
var uri = new Uri(possibleUrl);
|
||||||
|
|
||||||
using (var image = uri.GetAsAsync<Bitmap>().Result)
|
using var image = uri.GetAsAsync<Bitmap>().Result;
|
||||||
{
|
|
||||||
if (image != null)
|
if (image != null)
|
||||||
{
|
{
|
||||||
AddImageContainer(BitmapWrapper.FromBitmap(image), mouse.X, mouse.Y);
|
AddImageContainer(BitmapWrapper.FromBitmap(image), mouse.X, mouse.Y);
|
||||||
|
@ -2063,7 +2062,6 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var image in ClipboardHelper.GetBitmaps(e.Data))
|
foreach (var image in ClipboardHelper.GetBitmaps(e.Data))
|
||||||
{
|
{
|
||||||
|
|
|
@ -262,8 +262,8 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
};
|
};
|
||||||
|
|
||||||
_textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
|
_textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
|
||||||
_textBox.LostFocus += textBox_LostFocus;
|
_textBox.LostFocus += TextBox_LostFocus;
|
||||||
_textBox.KeyDown += textBox_KeyDown;
|
_textBox.KeyDown += TextBox_KeyDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowTextBox()
|
private void ShowTextBox()
|
||||||
|
@ -306,8 +306,11 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
_parent.Focus();
|
_parent.Focus();
|
||||||
_textBox?.Hide();
|
_textBox?.Hide();
|
||||||
_parent.KeysLocked = false;
|
_parent.KeysLocked = false;
|
||||||
|
if (_textBox != null)
|
||||||
|
{
|
||||||
_parent.Controls.Remove(_textBox);
|
_parent.Controls.Remove(_textBox);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make sure the size of the font is scaled
|
/// Make sure the size of the font is scaled
|
||||||
|
@ -336,8 +339,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
var fontStyle = FontStyle.Regular;
|
var fontStyle = FontStyle.Regular;
|
||||||
|
|
||||||
bool hasStyle = false;
|
bool hasStyle = false;
|
||||||
using (var fontFamily = new FontFamily(fontFamilyName))
|
using var fontFamily = new FontFamily(fontFamilyName);
|
||||||
{
|
|
||||||
bool boldAvailable = fontFamily.IsStyleAvailable(FontStyle.Bold);
|
bool boldAvailable = fontFamily.IsStyleAvailable(FontStyle.Bold);
|
||||||
if (fontBold && boldAvailable)
|
if (fontBold && boldAvailable)
|
||||||
{
|
{
|
||||||
|
@ -373,7 +375,6 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
}
|
}
|
||||||
return new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
|
return new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate the Font-Formal so we can draw correctly
|
/// Generate the Font-Formal so we can draw correctly
|
||||||
|
@ -487,7 +488,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
_textBox.ForeColor = lineColor;
|
_textBox.ForeColor = lineColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void textBox_KeyDown(object sender, KeyEventArgs e)
|
private void TextBox_KeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
// ESC and Enter/Return (w/o Shift) hide text editor
|
// ESC and Enter/Return (w/o Shift) hide text editor
|
||||||
if (e.KeyCode == Keys.Escape || ((e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) && e.Modifiers == Keys.None))
|
if (e.KeyCode == Keys.Escape || ((e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) && e.Modifiers == Keys.None))
|
||||||
|
@ -518,7 +519,7 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void textBox_LostFocus(object sender, EventArgs e)
|
private void TextBox_LostFocus(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// next change will be made undoable
|
// next change will be made undoable
|
||||||
makeUndoable = true;
|
makeUndoable = true;
|
||||||
|
@ -593,14 +594,13 @@ namespace Greenshot.Addon.LegacyEditor.Drawing
|
||||||
{
|
{
|
||||||
shadowRect = shadowRect.Inflate(-textOffset, -textOffset);
|
shadowRect = shadowRect.Inflate(-textOffset, -textOffset);
|
||||||
}
|
}
|
||||||
using (Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100)))
|
|
||||||
{
|
using Brush fontBrush = new SolidBrush(Color.FromArgb(alpha, 100, 100, 100));
|
||||||
graphics.DrawString(text, font, fontBrush, (Rectangle)shadowRect, stringFormat);
|
graphics.DrawString(text, font, fontBrush, (Rectangle)shadowRect, stringFormat);
|
||||||
currentStep++;
|
currentStep++;
|
||||||
alpha = alpha - basealpha / steps;
|
alpha = alpha - basealpha / steps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (lineThickness > 0)
|
if (lineThickness > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,13 +66,13 @@ namespace Greenshot.Addon.LegacyEditor
|
||||||
{
|
{
|
||||||
switch (fieldType.ValueType)
|
switch (fieldType.ValueType)
|
||||||
{
|
{
|
||||||
case var intType when fieldType.ValueType == typeof(int):
|
case var _ when fieldType.ValueType == typeof(int):
|
||||||
fieldValue = Convert.ToInt32(preferredValue);
|
fieldValue = Convert.ToInt32(preferredValue);
|
||||||
break;
|
break;
|
||||||
case var boolType when fieldType.ValueType == typeof(bool):
|
case var _ when fieldType.ValueType == typeof(bool):
|
||||||
fieldValue = Convert.ToBoolean(preferredValue);
|
fieldValue = Convert.ToBoolean(preferredValue);
|
||||||
break;
|
break;
|
||||||
case var colorType when fieldType.ValueType == typeof(Color):
|
case var _ when fieldType.ValueType == typeof(Color):
|
||||||
var color = Color.FromName(preferredStringValue);
|
var color = Color.FromName(preferredStringValue);
|
||||||
fieldValue = color;
|
fieldValue = color;
|
||||||
if (Color.Empty == color)
|
if (Color.Empty == color)
|
||||||
|
@ -80,22 +80,22 @@ namespace Greenshot.Addon.LegacyEditor
|
||||||
fieldValue = Color.FromArgb(Convert.ToInt32(preferredValue));
|
fieldValue = Color.FromArgb(Convert.ToInt32(preferredValue));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case var alignType when fieldType.ValueType == typeof(StringAlignment):
|
case var _ when fieldType.ValueType == typeof(StringAlignment):
|
||||||
fieldValue = Enum.Parse(typeof(StringAlignment), preferredStringValue, true);
|
fieldValue = Enum.Parse(typeof(StringAlignment), preferredStringValue, true);
|
||||||
break;
|
break;
|
||||||
case var fieldFlagType when fieldType.ValueType == typeof(FieldFlag):
|
case var _ when fieldType.ValueType == typeof(FieldFlag):
|
||||||
fieldValue = Enum.Parse(typeof(FieldFlag), preferredStringValue, true);
|
fieldValue = Enum.Parse(typeof(FieldFlag), preferredStringValue, true);
|
||||||
break;
|
break;
|
||||||
case var preparedFilterType when fieldType.ValueType == typeof(PreparedFilter):
|
case var _ when fieldType.ValueType == typeof(PreparedFilter):
|
||||||
fieldValue = Enum.Parse(typeof(PreparedFilter), preferredStringValue, true);
|
fieldValue = Enum.Parse(typeof(PreparedFilter), preferredStringValue, true);
|
||||||
break;
|
break;
|
||||||
case var arrowHeadCombinationType when fieldType.ValueType == typeof(ArrowContainer.ArrowHeadCombination):
|
case var _ when fieldType.ValueType == typeof(ArrowContainer.ArrowHeadCombination):
|
||||||
fieldValue = Enum.Parse(typeof(ArrowContainer.ArrowHeadCombination), preferredStringValue, true);
|
fieldValue = Enum.Parse(typeof(ArrowContainer.ArrowHeadCombination), preferredStringValue, true);
|
||||||
break;
|
break;
|
||||||
case var floatType when fieldType.ValueType == typeof(float):
|
case var _ when fieldType.ValueType == typeof(float):
|
||||||
fieldValue = Convert.ToSingle(preferredValue, CultureInfo.InvariantCulture);
|
fieldValue = Convert.ToSingle(preferredValue, CultureInfo.InvariantCulture);
|
||||||
break;
|
break;
|
||||||
case var doubleType when fieldType.ValueType == typeof(double):
|
case var _ when fieldType.ValueType == typeof(double):
|
||||||
fieldValue = Convert.ToDouble(preferredValue, CultureInfo.InvariantCulture);
|
fieldValue = Convert.ToDouble(preferredValue, CultureInfo.InvariantCulture);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace Greenshot.Addon.LegacyEditor.Forms {
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_destinationScaleHandler.Dispose();
|
||||||
// Make sure that clipboard changes are not longer processed.
|
// Make sure that clipboard changes are not longer processed.
|
||||||
_clipboardSubscription?.Dispose();
|
_clipboardSubscription?.Dispose();
|
||||||
// Remove all other stuff
|
// Remove all other stuff
|
||||||
|
|
|
@ -350,8 +350,7 @@ namespace Greenshot.Addon.LegacyEditor.Forms
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void PropertiesToolStrip_Paint(object sender, PaintEventArgs e)
|
private void PropertiesToolStrip_Paint(object sender, PaintEventArgs e)
|
||||||
{
|
{
|
||||||
using (var cbBorderPen = new Pen(SystemColors.ActiveBorder))
|
using var cbBorderPen = new Pen(SystemColors.ActiveBorder);
|
||||||
{
|
|
||||||
// Loop over all items in the propertiesToolStrip
|
// Loop over all items in the propertiesToolStrip
|
||||||
foreach (ToolStripItem item in propertiesToolStrip.Items)
|
foreach (ToolStripItem item in propertiesToolStrip.Items)
|
||||||
{
|
{
|
||||||
|
@ -370,7 +369,6 @@ namespace Greenshot.Addon.LegacyEditor.Forms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all the destinations and display them in the file menu and the buttons
|
/// Get all the destinations and display them in the file menu and the buttons
|
||||||
|
@ -901,15 +899,14 @@ namespace Greenshot.Addon.LegacyEditor.Forms
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using (Stream streamWrite = File.OpenWrite(saveFileDialog.FileName))
|
|
||||||
{
|
using Stream streamWrite = File.OpenWrite(saveFileDialog.FileName);
|
||||||
_surface.SaveElementsToStream(streamWrite);
|
_surface.SaveElementsToStream(streamWrite);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadElementsToolStripMenuItemClick(object sender, EventArgs e)
|
private void LoadElementsToolStripMenuItemClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var openFileDialog = new OpenFileDialog
|
using var openFileDialog = new OpenFileDialog
|
||||||
{
|
{
|
||||||
Filter = "Greenshot templates (*.gst)|*.gst"
|
Filter = "Greenshot templates (*.gst)|*.gst"
|
||||||
};
|
};
|
||||||
|
@ -1105,8 +1102,7 @@ namespace Greenshot.Addon.LegacyEditor.Forms
|
||||||
private void BtnResizeClick(object sender, EventArgs e)
|
private void BtnResizeClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var resizeEffect = new ResizeEffect(_surface.Screenshot.Width, _surface.Screenshot.Height, true);
|
var resizeEffect = new ResizeEffect(_surface.Screenshot.Width, _surface.Screenshot.Height, true);
|
||||||
using (var resizeSettingsForm = _resizeSettingsFormFactory(resizeEffect))
|
using var resizeSettingsForm = _resizeSettingsFormFactory(resizeEffect);
|
||||||
{
|
|
||||||
var result = resizeSettingsForm.Value.ShowDialog(this);
|
var result = resizeSettingsForm.Value.ShowDialog(this);
|
||||||
if (result == DialogResult.OK)
|
if (result == DialogResult.OK)
|
||||||
{
|
{
|
||||||
|
@ -1114,7 +1110,6 @@ namespace Greenshot.Addon.LegacyEditor.Forms
|
||||||
UpdateUndoRedoSurfaceDependencies();
|
UpdateUndoRedoSurfaceDependencies();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is used when the torn-edge button is used
|
/// This is used when the torn-edge button is used
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System.ComponentModel;
|
|
||||||
using Dapplo.Config.Language;
|
using Dapplo.Config.Language;
|
||||||
|
|
||||||
namespace Greenshot.Addon.Lutim.Configuration
|
namespace Greenshot.Addon.Lutim.Configuration
|
||||||
|
|
|
@ -48,12 +48,10 @@ namespace Greenshot.Addon.Lutim.Entities
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
using (var memoryStream = new MemoryStream(Convert.FromBase64String(ThumbBase64)))
|
using var memoryStream = new MemoryStream(Convert.FromBase64String(ThumbBase64));
|
||||||
{
|
|
||||||
return Image.FromStream(memoryStream);
|
return Image.FromStream(memoryStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[JsonProperty("filename")]
|
[JsonProperty("filename")]
|
||||||
public string Filename { get; set; }
|
public string Filename { get; set; }
|
||||||
|
|
|
@ -29,7 +29,6 @@ using Dapplo.HttpExtensions;
|
||||||
using Dapplo.Log;
|
using Dapplo.Log;
|
||||||
using Greenshot.Addon.Lutim.Configuration;
|
using Greenshot.Addon.Lutim.Configuration;
|
||||||
using Greenshot.Addon.Lutim.Entities;
|
using Greenshot.Addon.Lutim.Entities;
|
||||||
using Greenshot.Addons.Core;
|
|
||||||
using Greenshot.Addons.Interfaces;
|
using Greenshot.Addons.Interfaces;
|
||||||
|
|
||||||
namespace Greenshot.Addon.Lutim
|
namespace Greenshot.Addon.Lutim
|
||||||
|
@ -41,12 +40,10 @@ namespace Greenshot.Addon.Lutim
|
||||||
{
|
{
|
||||||
private static readonly LogSource Log = new LogSource();
|
private static readonly LogSource Log = new LogSource();
|
||||||
private readonly ILutimConfiguration _lutimConfiguration;
|
private readonly ILutimConfiguration _lutimConfiguration;
|
||||||
private readonly ICoreConfiguration _coreConfiguration;
|
|
||||||
|
|
||||||
public LutimApi(ILutimConfiguration lutimConfiguration, ICoreConfiguration coreConfiguration)
|
public LutimApi(ILutimConfiguration lutimConfiguration)
|
||||||
{
|
{
|
||||||
_lutimConfiguration = lutimConfiguration;
|
_lutimConfiguration = lutimConfiguration;
|
||||||
_coreConfiguration = coreConfiguration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -87,13 +84,13 @@ namespace Greenshot.Addon.Lutim
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
Log.Info().WriteLine("Bad format of lutim history item for short {0}", key);
|
Log.Info().WriteLine("Bad format of Lutim history item for short {0}", key);
|
||||||
_lutimConfiguration.LutimUploadHistory.Remove(key);
|
_lutimConfiguration.LutimUploadHistory.Remove(key);
|
||||||
_lutimConfiguration.RuntimeLutimHistory.Remove(key);
|
_lutimConfiguration.RuntimeLutimHistory.Remove(key);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error().WriteLine(e, "Problem loading lutim history for short " + key);
|
Log.Error().WriteLine(e, "Problem loading Lutim history for short " + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,14 +84,13 @@ namespace Greenshot.Addon.Lutim {
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override IBitmapWithNativeSupport DisplayIcon {
|
public override IBitmapWithNativeSupport DisplayIcon {
|
||||||
get {
|
get
|
||||||
// TODO: Optimize this by caching
|
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "Lutim.png"))
|
|
||||||
{
|
{
|
||||||
|
// TODO: Optimize this by caching
|
||||||
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "Lutim.png");
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
||||||
|
@ -155,12 +154,10 @@ namespace Greenshot.Addon.Lutim {
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(uploadUrl);
|
clipboardAccessToken.SetAsUrl(uploadUrl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error().WriteLine(ex, "Can't write to clipboard: ");
|
Log.Error().WriteLine(ex, "Can't write to clipboard: ");
|
||||||
|
|
|
@ -181,12 +181,10 @@ namespace Greenshot.Addon.Lutim.ViewModels
|
||||||
public void CopyToClipboard()
|
public void CopyToClipboard()
|
||||||
{
|
{
|
||||||
// TODO: Build url
|
// TODO: Build url
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(SelectedLutim.LutimInfo.Short);
|
clipboardAccessToken.SetAsUrl(SelectedLutim.LutimInfo.Short);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clear the whole history
|
/// Clear the whole history
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace Greenshot.Addon.Office.Destinations
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor used for dependency wiring
|
/// Constructor used for dependency wiring
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="oneNoteExporter">OneNoteExporter</param>
|
||||||
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
||||||
/// <param name="greenshotLanguage">IGreenshotLanguage</param>
|
/// <param name="greenshotLanguage">IGreenshotLanguage</param>
|
||||||
/// <param name="exportNotification">ExportNotification</param>
|
/// <param name="exportNotification">ExportNotification</param>
|
||||||
|
@ -59,7 +60,7 @@ namespace Greenshot.Addon.Office.Destinations
|
||||||
ExportNotification exportNotification
|
ExportNotification exportNotification
|
||||||
) : base(coreConfiguration, greenshotLanguage)
|
) : base(coreConfiguration, greenshotLanguage)
|
||||||
{
|
{
|
||||||
this._oneNoteExporter = oneNoteExporter;
|
_oneNoteExporter = oneNoteExporter;
|
||||||
_exportNotification = exportNotification;
|
_exportNotification = exportNotification;
|
||||||
_exePath = PluginUtils.GetExePath("ONENOTE.EXE");
|
_exePath = PluginUtils.GetExePath("ONENOTE.EXE");
|
||||||
if (_exePath != null && !File.Exists(_exePath))
|
if (_exePath != null && !File.Exists(_exePath))
|
||||||
|
@ -71,6 +72,7 @@ namespace Greenshot.Addon.Office.Destinations
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor used for dependency wiring, and being able to specify a page
|
/// Constructor used for dependency wiring, and being able to specify a page
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="oneNoteExporter">OneNoteExporter</param>
|
||||||
/// <param name="page">OneNotePage</param>
|
/// <param name="page">OneNotePage</param>
|
||||||
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
||||||
/// <param name="greenshotLanguage">IGreenshotLanguage</param>
|
/// <param name="greenshotLanguage">IGreenshotLanguage</param>
|
||||||
|
|
|
@ -49,11 +49,9 @@ namespace Greenshot.Addon.Office
|
||||||
private bool HasApplication(string applicationName)
|
private bool HasApplication(string applicationName)
|
||||||
{
|
{
|
||||||
string registryPath = $@"{applicationName}\CLSID";
|
string registryPath = $@"{applicationName}\CLSID";
|
||||||
using (var registryKey = Registry.ClassesRoot.OpenSubKey(registryPath, false))
|
using var registryKey = Registry.ClassesRoot.OpenSubKey(registryPath, false);
|
||||||
{
|
|
||||||
return registryKey != null && Guid.TryParse(registryKey.GetValue(null) as string, out _);
|
return registryKey != null && Guid.TryParse(registryKey.GetValue(null) as string, out _);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Define the dependencies of this project
|
/// Define the dependencies of this project
|
||||||
|
|
|
@ -82,27 +82,22 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <returns>IEnumerable with names of the workbooks</returns>
|
/// <returns>IEnumerable with names of the workbooks</returns>
|
||||||
public static IEnumerable<string> GetWorkbooks()
|
public static IEnumerable<string> GetWorkbooks()
|
||||||
{
|
{
|
||||||
using (var excelApplication = GetExcelApplication())
|
using var excelApplication = GetExcelApplication();
|
||||||
{
|
|
||||||
if ((excelApplication == null) || (excelApplication.ComObject == null))
|
if ((excelApplication == null) || (excelApplication.ComObject == null))
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
using (var workbooks = DisposableCom.Create(excelApplication.ComObject.Workbooks))
|
|
||||||
{
|
using var workbooks = DisposableCom.Create(excelApplication.ComObject.Workbooks);
|
||||||
for (int i = 1; i <= workbooks.ComObject.Count; i++)
|
for (int i = 1; i <= workbooks.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var workbook = DisposableCom.Create(workbooks.ComObject[i]))
|
using var workbook = DisposableCom.Create(workbooks.ComObject[i]);
|
||||||
{
|
|
||||||
if (workbook != null)
|
if (workbook != null)
|
||||||
{
|
{
|
||||||
yield return workbook.ComObject.Name;
|
yield return workbook.ComObject.Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize static excel variables like version and currentuser
|
/// Initialize static excel variables like version and currentuser
|
||||||
|
@ -129,27 +124,22 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <param name="imageSize"></param>
|
/// <param name="imageSize"></param>
|
||||||
public static void InsertIntoExistingWorkbook(string workbookName, string tmpFile, Size imageSize)
|
public static void InsertIntoExistingWorkbook(string workbookName, string tmpFile, Size imageSize)
|
||||||
{
|
{
|
||||||
using (var excelApplication = GetExcelApplication())
|
using var excelApplication = GetExcelApplication();
|
||||||
{
|
|
||||||
if ((excelApplication == null) || (excelApplication.ComObject == null))
|
if ((excelApplication == null) || (excelApplication.ComObject == null))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using (var workbooks = DisposableCom.Create(excelApplication.ComObject.Workbooks))
|
|
||||||
{
|
using var workbooks = DisposableCom.Create(excelApplication.ComObject.Workbooks);
|
||||||
for (int i = 1; i <= workbooks.ComObject.Count; i++)
|
for (int i = 1; i <= workbooks.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var workbook = DisposableCom.Create((_Workbook)workbooks.ComObject[i]))
|
using var workbook = DisposableCom.Create((_Workbook)workbooks.ComObject[i]);
|
||||||
{
|
|
||||||
if ((workbook != null) && workbook.ComObject.Name.StartsWith(workbookName))
|
if ((workbook != null) && workbook.ComObject.Name.StartsWith(workbookName))
|
||||||
{
|
{
|
||||||
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
|
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Insert a file into an already created workbook
|
/// Insert a file into an already created workbook
|
||||||
|
@ -159,21 +149,19 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <param name="imageSize"></param>
|
/// <param name="imageSize"></param>
|
||||||
private static void InsertIntoExistingWorkbook(IDisposableCom<_Workbook> workbook, string tmpFile, Size imageSize)
|
private static void InsertIntoExistingWorkbook(IDisposableCom<_Workbook> workbook, string tmpFile, Size imageSize)
|
||||||
{
|
{
|
||||||
using (var workSheet = DisposableCom.Create(workbook.ComObject.ActiveSheet as Worksheet))
|
using var workSheet = DisposableCom.Create(workbook.ComObject.ActiveSheet as Worksheet);
|
||||||
{
|
|
||||||
if (workSheet == null)
|
if (workSheet == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using (var shapes = DisposableCom.Create(workSheet.ComObject.Shapes))
|
|
||||||
{
|
using var shapes = DisposableCom.Create(workSheet.ComObject.Shapes);
|
||||||
if (shapes == null)
|
if (shapes == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var shape = DisposableCom.Create(shapes.ComObject.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, imageSize.Width, imageSize.Height)))
|
using var shape = DisposableCom.Create(shapes.ComObject.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, imageSize.Width, imageSize.Height));
|
||||||
{
|
|
||||||
if (shape == null)
|
if (shape == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -185,15 +173,10 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
shape.ComObject.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
|
shape.ComObject.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
|
||||||
shape.ComObject.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
|
shape.ComObject.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
|
||||||
workbook.ComObject.Activate();
|
workbook.ComObject.Activate();
|
||||||
using (var application = DisposableCom.Create(workbook.ComObject.Application))
|
using var application = DisposableCom.Create(workbook.ComObject.Application);
|
||||||
{
|
|
||||||
var excelWindow = InteropWindowFactory.CreateFor((IntPtr) application.ComObject.Hwnd);
|
var excelWindow = InteropWindowFactory.CreateFor((IntPtr) application.ComObject.Hwnd);
|
||||||
excelWindow.ToForegroundAsync();
|
excelWindow.ToForegroundAsync();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add an image-file to a newly created workbook
|
/// Add an image-file to a newly created workbook
|
||||||
|
@ -202,23 +185,17 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <param name="imageSize"></param>
|
/// <param name="imageSize"></param>
|
||||||
public static void InsertIntoNewWorkbook(string tmpFile, Size imageSize)
|
public static void InsertIntoNewWorkbook(string tmpFile, Size imageSize)
|
||||||
{
|
{
|
||||||
using (var excelApplication = GetOrCreateExcelApplication())
|
using var excelApplication = GetOrCreateExcelApplication();
|
||||||
{
|
|
||||||
if (excelApplication == null)
|
if (excelApplication == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
excelApplication.ComObject.Visible = true;
|
excelApplication.ComObject.Visible = true;
|
||||||
using (var workbooks = DisposableCom.Create(excelApplication.ComObject.Workbooks))
|
using var workbooks = DisposableCom.Create(excelApplication.ComObject.Workbooks);
|
||||||
{
|
using var workbook = DisposableCom.Create((_Workbook)workbooks.ComObject.Add());
|
||||||
using (var workbook = DisposableCom.Create((_Workbook)workbooks.ComObject.Add()))
|
|
||||||
{
|
|
||||||
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
|
InsertIntoExistingWorkbook(workbook, tmpFile, imageSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -57,8 +57,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <returns>bool true if export worked</returns>
|
/// <returns>bool true if export worked</returns>
|
||||||
public bool ExportToNewPage(ISurface surfaceToUpload)
|
public bool ExportToNewPage(ISurface surfaceToUpload)
|
||||||
{
|
{
|
||||||
using (var oneNoteApplication = GetOrCreateOneNoteApplication())
|
using var oneNoteApplication = GetOrCreateOneNoteApplication();
|
||||||
{
|
|
||||||
var newPage = new OneNotePage();
|
var newPage = new OneNotePage();
|
||||||
string unfiledNotesSectionId = GetSectionId(oneNoteApplication, SpecialLocation.slUnfiledNotesSection);
|
string unfiledNotesSectionId = GetSectionId(oneNoteApplication, SpecialLocation.slUnfiledNotesSection);
|
||||||
if (unfiledNotesSectionId == null)
|
if (unfiledNotesSectionId == null)
|
||||||
|
@ -73,7 +72,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
newPage.Name = surfaceToUpload.CaptureDetails.Title;
|
newPage.Name = surfaceToUpload.CaptureDetails.Title;
|
||||||
return ExportToPage(oneNoteApplication, surfaceToUpload, newPage);
|
return ExportToPage(oneNoteApplication, surfaceToUpload, newPage);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Export the capture to the specified page
|
/// Export the capture to the specified page
|
||||||
|
@ -83,11 +81,9 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <returns>bool true if everything worked</returns>
|
/// <returns>bool true if everything worked</returns>
|
||||||
public bool ExportToPage(ISurface surfaceToUpload, OneNotePage page)
|
public bool ExportToPage(ISurface surfaceToUpload, OneNotePage page)
|
||||||
{
|
{
|
||||||
using (var oneNoteApplication = GetOrCreateOneNoteApplication())
|
using var oneNoteApplication = GetOrCreateOneNoteApplication();
|
||||||
{
|
|
||||||
return ExportToPage(oneNoteApplication, surfaceToUpload, page);
|
return ExportToPage(oneNoteApplication, surfaceToUpload, page);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Export the capture to the specified page
|
/// Export the capture to the specified page
|
||||||
|
@ -103,8 +99,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var pngStream = new MemoryStream())
|
using var pngStream = new MemoryStream();
|
||||||
{
|
|
||||||
var pngOutputSettings = new SurfaceOutputSettings(_coreConfiguration, OutputFormats.png, 100, false);
|
var pngOutputSettings = new SurfaceOutputSettings(_coreConfiguration, OutputFormats.png, 100, false);
|
||||||
ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
|
ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
|
||||||
var base64String = Convert.ToBase64String(pngStream.GetBuffer());
|
var base64String = Convert.ToBase64String(pngStream.GetBuffer());
|
||||||
|
@ -122,7 +117,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this to get the running Excel application, returns null if there isn't any.
|
/// Call this to get the running Excel application, returns null if there isn't any.
|
||||||
|
@ -166,8 +160,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
var pages = new List<OneNotePage>();
|
var pages = new List<OneNotePage>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var oneNoteApplication = GetOrCreateOneNoteApplication())
|
using var oneNoteApplication = GetOrCreateOneNoteApplication();
|
||||||
{
|
|
||||||
if (oneNoteApplication != null)
|
if (oneNoteApplication != null)
|
||||||
{
|
{
|
||||||
// ReSharper disable once RedundantAssignment
|
// ReSharper disable once RedundantAssignment
|
||||||
|
@ -180,8 +173,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
reader = new StringReader(notebookXml);
|
reader = new StringReader(notebookXml);
|
||||||
using (var xmlReader = new XmlTextReader(reader))
|
using var xmlReader = new XmlTextReader(reader);
|
||||||
{
|
|
||||||
reader = null;
|
reader = null;
|
||||||
OneNoteSection currentSection = null;
|
OneNoteSection currentSection = null;
|
||||||
OneNoteNotebook currentNotebook = null;
|
OneNoteNotebook currentNotebook = null;
|
||||||
|
@ -192,15 +184,17 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
string id = xmlReader.GetAttribute("ID");
|
string id = xmlReader.GetAttribute("ID");
|
||||||
if ((id != null) && ((currentNotebook == null) || !id.Equals(currentNotebook.Id)))
|
if ((id != null) && ((currentNotebook == null) || !id.Equals(currentNotebook.Id)))
|
||||||
{
|
{
|
||||||
currentNotebook = new OneNoteNotebook();
|
currentNotebook = new OneNoteNotebook
|
||||||
currentNotebook.Id = xmlReader.GetAttribute("ID");
|
{
|
||||||
currentNotebook.Name = xmlReader.GetAttribute("name");
|
Id = xmlReader.GetAttribute("ID"),
|
||||||
|
Name = xmlReader.GetAttribute("name")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ("one:Section".Equals(xmlReader.Name))
|
if ("one:Section".Equals(xmlReader.Name))
|
||||||
{
|
{
|
||||||
string id = xmlReader.GetAttribute("ID");
|
string id = xmlReader.GetAttribute("ID");
|
||||||
if ((id != null) && ((currentSection == null) || !id.Equals(currentSection.Id)))
|
if (id != null && (currentSection == null || !id.Equals(currentSection.Id)))
|
||||||
{
|
{
|
||||||
currentSection = new OneNoteSection
|
currentSection = new OneNoteSection
|
||||||
{
|
{
|
||||||
|
@ -233,7 +227,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (reader != null)
|
if (reader != null)
|
||||||
|
@ -244,7 +237,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (COMException cEx)
|
catch (COMException cEx)
|
||||||
{
|
{
|
||||||
if (cEx.ErrorCode == unchecked((int)0x8002801D))
|
if (cEx.ErrorCode == unchecked((int)0x8002801D))
|
||||||
|
@ -294,8 +286,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
reader = new StringReader(notebookXml);
|
reader = new StringReader(notebookXml);
|
||||||
using (var xmlReader = new XmlTextReader(reader))
|
using var xmlReader = new XmlTextReader(reader);
|
||||||
{
|
|
||||||
while (xmlReader.Read())
|
while (xmlReader.Read())
|
||||||
{
|
{
|
||||||
if (!"one:Section".Equals(xmlReader.Name))
|
if (!"one:Section".Equals(xmlReader.Name))
|
||||||
|
@ -310,7 +301,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (reader != null)
|
if (reader != null)
|
||||||
|
|
|
@ -86,8 +86,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
if (_outlookVersion.Major >= (int)OfficeVersions.Office2013)
|
if (_outlookVersion.Major >= (int)OfficeVersions.Office2013)
|
||||||
{
|
{
|
||||||
// Check inline "panel" for Outlook 2013
|
// Check inline "panel" for Outlook 2013
|
||||||
using (var activeExplorer = DisposableCom.Create((_Explorer)outlookApplication.ComObject.ActiveExplorer()))
|
using var activeExplorer = DisposableCom.Create((_Explorer)outlookApplication.ComObject.ActiveExplorer());
|
||||||
{
|
|
||||||
// Only if we have one and if the capture is the one we selected
|
// Only if we have one and if the capture is the one we selected
|
||||||
if ((activeExplorer != null) && activeExplorer.ComObject.Caption.StartsWith(inspectorCaption))
|
if ((activeExplorer != null) && activeExplorer.ComObject.Caption.StartsWith(inspectorCaption))
|
||||||
{
|
{
|
||||||
|
@ -115,10 +114,8 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
using (var inspectors = DisposableCom.Create(outlookApplication.ComObject.Inspectors))
|
using var inspectors = DisposableCom.Create(outlookApplication.ComObject.Inspectors);
|
||||||
{
|
|
||||||
if ((inspectors == null) || (inspectors.ComObject.Count == 0))
|
if ((inspectors == null) || (inspectors.ComObject.Count == 0))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -126,8 +123,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
Log.Debug().WriteLine("Got {0} inspectors to check", inspectors.ComObject.Count);
|
Log.Debug().WriteLine("Got {0} inspectors to check", inspectors.ComObject.Count);
|
||||||
for (int i = 1; i <= inspectors.ComObject.Count; i++)
|
for (int i = 1; i <= inspectors.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var inspector = DisposableCom.Create((_Inspector)inspectors.ComObject[i]))
|
using var inspector = DisposableCom.Create((_Inspector)inspectors.ComObject[i]);
|
||||||
{
|
|
||||||
string currentCaption = inspector.ComObject.Caption;
|
string currentCaption = inspector.ComObject.Caption;
|
||||||
if (!currentCaption.StartsWith(inspectorCaption))
|
if (!currentCaption.StartsWith(inspectorCaption))
|
||||||
{
|
{
|
||||||
|
@ -182,8 +178,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,8 +233,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
{
|
{
|
||||||
using (wordDocument)
|
using (wordDocument)
|
||||||
{
|
{
|
||||||
using (var application = DisposableCom.Create(wordDocument.ComObject.Application))
|
using var application = DisposableCom.Create(wordDocument.ComObject.Application);
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_wordExporter.InsertIntoExistingDocument(application, wordDocument, tmpFile, null, null))
|
if (_wordExporter.InsertIntoExistingDocument(application, wordDocument, tmpFile, null, null))
|
||||||
|
@ -255,7 +248,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (isAppointment)
|
else if (isAppointment)
|
||||||
{
|
{
|
||||||
Log.Info().WriteLine("Can't export to an appointment if no word editor is used");
|
Log.Info().WriteLine("Can't export to an appointment if no word editor is used");
|
||||||
|
@ -296,8 +288,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
// The following might cause a security popup... can't ignore it.
|
// The following might cause a security popup... can't ignore it.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var document2 = inspector.ComObject.HTMLEditor as IHTMLDocument2;
|
if (inspector.ComObject.HTMLEditor is IHTMLDocument2 document2)
|
||||||
if (document2 != null)
|
|
||||||
{
|
{
|
||||||
var selection = document2.selection;
|
var selection = document2.selection;
|
||||||
if (selection != null)
|
if (selection != null)
|
||||||
|
@ -332,10 +323,8 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the attachment (if inlined the attachment isn't visible as attachment!)
|
// Create the attachment (if inlined the attachment isn't visible as attachment!)
|
||||||
using (var attachments = DisposableCom.Create(mailItem.Attachments))
|
using var attachments = DisposableCom.Create(mailItem.Attachments);
|
||||||
{
|
using var attachment = DisposableCom.Create(attachments.ComObject.Add(tmpFile, OlAttachmentType.olByValue, inlinePossible ? 0 : 1, attachmentName));
|
||||||
using (var attachment = DisposableCom.Create(attachments.ComObject.Add(tmpFile, OlAttachmentType.olByValue, inlinePossible ? 0 : 1, attachmentName)))
|
|
||||||
{
|
|
||||||
if (_outlookVersion.Major >= (int)OfficeVersions.Office2007)
|
if (_outlookVersion.Major >= (int)OfficeVersions.Office2007)
|
||||||
{
|
{
|
||||||
// Add the content id to the attachment, this only works for Outlook >= 2007
|
// Add the content id to the attachment, this only works for Outlook >= 2007
|
||||||
|
@ -351,8 +340,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
string caption = "n.a.";
|
string caption = "n.a.";
|
||||||
|
@ -401,8 +388,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
private void ExportToNewEmail(IDisposableCom<Application> outlookApplication, EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string cc, string bcc, string url)
|
private void ExportToNewEmail(IDisposableCom<Application> outlookApplication, EmailFormat format, string tmpFile, string subject, string attachmentName, string to, string cc, string bcc, string url)
|
||||||
{
|
{
|
||||||
using (var newItem = DisposableCom.Create((MailItem)outlookApplication.ComObject.CreateItem(OlItemType.olMailItem)))
|
using var newItem = DisposableCom.Create((MailItem)outlookApplication.ComObject.CreateItem(OlItemType.olMailItem));
|
||||||
{
|
|
||||||
if (newItem == null)
|
if (newItem == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -454,19 +440,16 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
// Create the attachment (and dispose the COM object after using)
|
// Create the attachment (and dispose the COM object after using)
|
||||||
using (var attachments = DisposableCom.Create(newMail.Attachments))
|
using (var attachments = DisposableCom.Create(newMail.Attachments))
|
||||||
{
|
{
|
||||||
using (var attachment = DisposableCom.Create(attachments.ComObject.Add(tmpFile, OlAttachmentType.olByValue, 0, attachmentName)))
|
using var attachment = DisposableCom.Create(attachments.ComObject.Add(tmpFile, OlAttachmentType.olByValue, 0, attachmentName));
|
||||||
{
|
|
||||||
// add content ID to the attachment
|
// add content ID to the attachment
|
||||||
if (_outlookVersion.Major >= (int)OfficeVersions.Office2007)
|
if (_outlookVersion.Major >= (int)OfficeVersions.Office2007)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
contentId = Guid.NewGuid().ToString();
|
contentId = Guid.NewGuid().ToString();
|
||||||
using (var propertyAccessor = DisposableCom.Create(attachment.ComObject.PropertyAccessor))
|
using var propertyAccessor = DisposableCom.Create(attachment.ComObject.PropertyAccessor);
|
||||||
{
|
|
||||||
propertyAccessor.ComObject.SetProperty(AttachmentContentId, contentId);
|
propertyAccessor.ComObject.SetProperty(AttachmentContentId, contentId);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Log.Info().WriteLine("Error working with the PropertyAccessor, using filename as contentid");
|
Log.Info().WriteLine("Error working with the PropertyAccessor, using filename as contentid");
|
||||||
|
@ -474,7 +457,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
newMail.BodyFormat = OlBodyFormat.olFormatHTML;
|
newMail.BodyFormat = OlBodyFormat.olFormatHTML;
|
||||||
string href = "";
|
string href = "";
|
||||||
|
@ -516,8 +498,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
// So not save, otherwise the email is always stored in Draft folder.. (newMail.Save();)
|
// So not save, otherwise the email is always stored in Draft folder.. (newMail.Save();)
|
||||||
newMail.Display(false);
|
newMail.Display(false);
|
||||||
|
|
||||||
using (var inspector = DisposableCom.Create((_Inspector)newMail.GetInspector))
|
using var inspector = DisposableCom.Create((_Inspector)newMail.GetInspector);
|
||||||
{
|
|
||||||
if (inspector != null)
|
if (inspector != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -531,8 +512,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper method to create an outlook mail item with attachment
|
/// Helper method to create an outlook mail item with attachment
|
||||||
|
@ -620,16 +599,14 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
string defaultProfile = (string)profilesKey.GetValue(DefaultProfileValue);
|
string defaultProfile = (string)profilesKey.GetValue(DefaultProfileValue);
|
||||||
Log.Debug().WriteLine("defaultProfile={0}", defaultProfile);
|
Log.Debug().WriteLine("defaultProfile={0}", defaultProfile);
|
||||||
using (var profileKey = profilesKey.OpenSubKey(defaultProfile + @"\" + AccountKey, false))
|
using var profileKey = profilesKey.OpenSubKey(defaultProfile + @"\" + AccountKey, false);
|
||||||
{
|
|
||||||
if (profileKey != null)
|
if (profileKey != null)
|
||||||
{
|
{
|
||||||
string[] numbers = profileKey.GetSubKeyNames();
|
string[] numbers = profileKey.GetSubKeyNames();
|
||||||
foreach (string number in numbers)
|
foreach (string number in numbers)
|
||||||
{
|
{
|
||||||
Log.Debug().WriteLine("Found subkey {0}", number);
|
Log.Debug().WriteLine("Found subkey {0}", number);
|
||||||
using (var numberKey = profileKey.OpenSubKey(number, false))
|
using var numberKey = profileKey.OpenSubKey(number, false);
|
||||||
{
|
|
||||||
if (numberKey != null)
|
if (numberKey != null)
|
||||||
{
|
{
|
||||||
byte[] val = (byte[])numberKey.GetValue(NewSignatureValue);
|
byte[] val = (byte[])numberKey.GetValue(NewSignatureValue);
|
||||||
|
@ -646,16 +623,11 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.Debug().WriteLine("Found email signature: {0}", signatureName);
|
Log.Debug().WriteLine("Found email signature: {0}", signatureName);
|
||||||
string extension;
|
var extension = format switch
|
||||||
switch (format)
|
|
||||||
{
|
{
|
||||||
case EmailFormat.Text:
|
EmailFormat.Text => ".txt",
|
||||||
extension = ".txt";
|
_ => ".htm"
|
||||||
break;
|
};
|
||||||
default:
|
|
||||||
extension = ".htm";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
string signatureFile = Path.Combine(SignaturePath, signatureName + extension);
|
string signatureFile = Path.Combine(SignaturePath, signatureName + extension);
|
||||||
if (File.Exists(signatureFile))
|
if (File.Exists(signatureFile))
|
||||||
{
|
{
|
||||||
|
@ -666,8 +638,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,11 +664,9 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
{
|
{
|
||||||
using (var mapiNamespace = DisposableCom.Create(outlookApplication.ComObject.GetNamespace("MAPI")))
|
using (var mapiNamespace = DisposableCom.Create(outlookApplication.ComObject.GetNamespace("MAPI")))
|
||||||
{
|
{
|
||||||
using (var currentUser = DisposableCom.Create(mapiNamespace.ComObject.CurrentUser))
|
using var currentUser = DisposableCom.Create(mapiNamespace.ComObject.CurrentUser);
|
||||||
{
|
|
||||||
_currentUser = currentUser.ComObject.Name;
|
_currentUser = currentUser.ComObject.Name;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Log.Info().WriteLine("Current user: {0}", _currentUser);
|
Log.Info().WriteLine("Current user: {0}", _currentUser);
|
||||||
}
|
}
|
||||||
catch (Exception exNs)
|
catch (Exception exNs)
|
||||||
|
@ -717,8 +685,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
IDictionary<string, OlObjectClass> inspectorCaptions = new SortedDictionary<string, OlObjectClass>();
|
IDictionary<string, OlObjectClass> inspectorCaptions = new SortedDictionary<string, OlObjectClass>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var outlookApplication = GetOutlookApplication())
|
using var outlookApplication = GetOutlookApplication();
|
||||||
{
|
|
||||||
if (outlookApplication == null)
|
if (outlookApplication == null)
|
||||||
{
|
{
|
||||||
return inspectorCaptions;
|
return inspectorCaptions;
|
||||||
|
@ -728,8 +695,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
if (_outlookVersion.Major >= (int)OfficeVersions.Office2013)
|
if (_outlookVersion.Major >= (int)OfficeVersions.Office2013)
|
||||||
{
|
{
|
||||||
// Check inline "panel" for Outlook 2013
|
// Check inline "panel" for Outlook 2013
|
||||||
using (var activeExplorer = DisposableCom.Create(outlookApplication.ComObject.ActiveExplorer()))
|
using var activeExplorer = DisposableCom.Create(outlookApplication.ComObject.ActiveExplorer());
|
||||||
{
|
|
||||||
if (activeExplorer != null)
|
if (activeExplorer != null)
|
||||||
{
|
{
|
||||||
var untypedInlineResponse = activeExplorer.ComObject.ActiveInlineResponse;
|
var untypedInlineResponse = activeExplorer.ComObject.ActiveInlineResponse;
|
||||||
|
@ -760,16 +726,13 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
using (var inspectors = DisposableCom.Create(outlookApplication.ComObject.Inspectors))
|
using var inspectors = DisposableCom.Create(outlookApplication.ComObject.Inspectors);
|
||||||
{
|
|
||||||
if ((inspectors != null) && (inspectors.ComObject.Count > 0))
|
if ((inspectors != null) && (inspectors.ComObject.Count > 0))
|
||||||
{
|
{
|
||||||
for (int i = 1; i <= inspectors.ComObject.Count; i++)
|
for (int i = 1; i <= inspectors.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var inspector = DisposableCom.Create(inspectors.ComObject[i]))
|
using var inspector = DisposableCom.Create(inspectors.ComObject[i]);
|
||||||
{
|
|
||||||
string caption = inspector.ComObject.Caption;
|
string caption = inspector.ComObject.Caption;
|
||||||
// Fix double entries in the directory, TODO: store on something uniq
|
// Fix double entries in the directory, TODO: store on something uniq
|
||||||
if (inspectorCaptions.ContainsKey(caption))
|
if (inspectorCaptions.ContainsKey(caption))
|
||||||
|
@ -812,9 +775,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(ex, "Problem retrieving word destinations, ignoring: ");
|
Log.Warn().WriteLine(ex, "Problem retrieving word destinations, ignoring: ");
|
||||||
|
|
|
@ -81,10 +81,8 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
slide = DisposableCom.Create(slides.ComObject.Add(slides.ComObject.Count + 1, _officeConfiguration.PowerpointSlideLayout));
|
slide = DisposableCom.Create(slides.ComObject.Add(slides.ComObject.Count + 1, _officeConfiguration.PowerpointSlideLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var shapes = DisposableCom.Create(slide.ComObject.Shapes))
|
using var shapes = DisposableCom.Create(slide.ComObject.Shapes);
|
||||||
{
|
using var shapeForLocation = DisposableCom.Create(shapes.ComObject[2]);
|
||||||
using (var shapeForLocation = DisposableCom.Create(shapes.ComObject[2]))
|
|
||||||
{
|
|
||||||
// Shapes[2] is the image shape on this layout.
|
// Shapes[2] is the image shape on this layout.
|
||||||
shapeForCaption = DisposableCom.Create(shapes.ComObject[1]);
|
shapeForCaption = DisposableCom.Create(shapes.ComObject[1]);
|
||||||
if (width > shapeForLocation.ComObject.Width)
|
if (width > shapeForLocation.ComObject.Width)
|
||||||
|
@ -111,20 +109,15 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
shapeForLocation.ComObject.Height = imageSize.Height;
|
shapeForLocation.ComObject.Height = imageSize.Height;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error().WriteLine(e, "Powerpoint shape creating failed");
|
Log.Error().WriteLine(e, "Powerpoint shape creating failed");
|
||||||
using (var slides = DisposableCom.Create(presentation.ComObject.Slides))
|
using var slides = DisposableCom.Create(presentation.ComObject.Slides);
|
||||||
{
|
|
||||||
slide = DisposableCom.Create(slides.ComObject.Add(slides.ComObject.Count + 1, PpSlideLayout.ppLayoutBlank));
|
slide = DisposableCom.Create(slides.ComObject.Add(slides.ComObject.Count + 1, PpSlideLayout.ppLayoutBlank));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
using (var shapes = DisposableCom.Create(slide.ComObject.Shapes))
|
using (var shapes = DisposableCom.Create(slide.ComObject.Shapes))
|
||||||
{
|
{
|
||||||
using (var shape = DisposableCom.Create(shapes.ComObject.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, width, height)))
|
using var shape = DisposableCom.Create(shapes.ComObject.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, width, height));
|
||||||
{
|
|
||||||
if (_officeConfiguration.PowerpointLockAspectRatio)
|
if (_officeConfiguration.PowerpointLockAspectRatio)
|
||||||
{
|
{
|
||||||
shape.ComObject.LockAspectRatio = MsoTriState.msoTrue;
|
shape.ComObject.LockAspectRatio = MsoTriState.msoTrue;
|
||||||
|
@ -147,7 +140,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
shape.ComObject.Top = top;
|
shape.ComObject.Top = top;
|
||||||
shape.ComObject.AlternativeText = title;
|
shape.ComObject.AlternativeText = title;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (shapeForCaption != null)
|
if (shapeForCaption != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -155,15 +147,11 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
using (shapeForCaption)
|
using (shapeForCaption)
|
||||||
{
|
{
|
||||||
// Using try/catch to make sure problems with the text range don't give an exception.
|
// Using try/catch to make sure problems with the text range don't give an exception.
|
||||||
using (var textFrame = DisposableCom.Create(shapeForCaption.ComObject.TextFrame))
|
using var textFrame = DisposableCom.Create(shapeForCaption.ComObject.TextFrame);
|
||||||
{
|
using var textRange = DisposableCom.Create(textFrame.ComObject.TextRange);
|
||||||
using (var textRange = DisposableCom.Create(textFrame.ComObject.TextRange))
|
|
||||||
{
|
|
||||||
textRange.ComObject.Text = title;
|
textRange.ComObject.Text = title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(ex, "Problem setting the title to a text-range");
|
Log.Warn().WriteLine(ex, "Problem setting the title to a text-range");
|
||||||
|
@ -172,17 +160,11 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
// Activate/Goto the slide
|
// Activate/Goto the slide
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var application = DisposableCom.Create(presentation.ComObject.Application))
|
using var application = DisposableCom.Create(presentation.ComObject.Application);
|
||||||
{
|
using var activeWindow = DisposableCom.Create(application.ComObject.ActiveWindow);
|
||||||
using (var activeWindow = DisposableCom.Create(application.ComObject.ActiveWindow))
|
using var view = DisposableCom.Create(activeWindow.ComObject.View);
|
||||||
{
|
|
||||||
using (var view = DisposableCom.Create(activeWindow.ComObject.View))
|
|
||||||
{
|
|
||||||
view.ComObject.GotoSlide(slide.ComObject.SlideNumber);
|
view.ComObject.GotoSlide(slide.ComObject.SlideNumber);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(ex, "Problem going to the slide");
|
Log.Warn().WriteLine(ex, "Problem going to the slide");
|
||||||
|
@ -211,13 +193,12 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
using (var presentations = DisposableCom.Create(powerpointApplication.ComObject.Presentations))
|
|
||||||
{
|
using var presentations = DisposableCom.Create(powerpointApplication.ComObject.Presentations);
|
||||||
Log.Debug().WriteLine("Open Presentations: {0}", presentations.ComObject.Count);
|
Log.Debug().WriteLine("Open Presentations: {0}", presentations.ComObject.Count);
|
||||||
for (int i = 1; i <= presentations.ComObject.Count; i++)
|
for (int i = 1; i <= presentations.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var presentation = DisposableCom.Create(presentations.ComObject[i]))
|
using var presentation = DisposableCom.Create(presentations.ComObject[i]);
|
||||||
{
|
|
||||||
if (presentation == null)
|
if (presentation == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -237,8 +218,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,20 +265,17 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<string> GetPowerpointPresentations()
|
public IEnumerable<string> GetPowerpointPresentations()
|
||||||
{
|
{
|
||||||
using (var powerpointApplication = GetPowerPointApplication())
|
using var powerpointApplication = GetPowerPointApplication();
|
||||||
{
|
|
||||||
if (powerpointApplication == null)
|
if (powerpointApplication == null)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var presentations = DisposableCom.Create(powerpointApplication.ComObject.Presentations))
|
using var presentations = DisposableCom.Create(powerpointApplication.ComObject.Presentations);
|
||||||
{
|
|
||||||
Log.Debug().WriteLine("Open Presentations: {0}", presentations.ComObject.Count);
|
Log.Debug().WriteLine("Open Presentations: {0}", presentations.ComObject.Count);
|
||||||
for (int i = 1; i <= presentations.ComObject.Count; i++)
|
for (int i = 1; i <= presentations.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var presentation = DisposableCom.Create(presentations.ComObject[i]))
|
using var presentation = DisposableCom.Create(presentations.ComObject[i]);
|
||||||
{
|
|
||||||
if (presentation == null)
|
if (presentation == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -318,9 +294,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
yield return presentation.ComObject.Name;
|
yield return presentation.ComObject.Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize static powerpoint variables like version
|
/// Initialize static powerpoint variables like version
|
||||||
|
@ -355,10 +328,8 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
{
|
{
|
||||||
powerpointApplication.ComObject.Activate();
|
powerpointApplication.ComObject.Activate();
|
||||||
powerpointApplication.ComObject.Visible = MsoTriState.msoTrue;
|
powerpointApplication.ComObject.Visible = MsoTriState.msoTrue;
|
||||||
using (var presentations = DisposableCom.Create(powerpointApplication.ComObject.Presentations))
|
using var presentations = DisposableCom.Create(powerpointApplication.ComObject.Presentations);
|
||||||
{
|
using var presentation = DisposableCom.Create(presentations.ComObject.Add());
|
||||||
using (var presentation = DisposableCom.Create(presentations.ComObject.Add()))
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AddPictureToPresentation(presentation, tmpFile, imageSize, title);
|
AddPictureToPresentation(presentation, tmpFile, imageSize, title);
|
||||||
|
@ -370,8 +341,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return isPictureAdded;
|
return isPictureAdded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private IDisposableCom<InlineShape> AddPictureToSelection(IDisposableCom<Selection> selection, string tmpFile)
|
private IDisposableCom<InlineShape> AddPictureToSelection(IDisposableCom<Selection> selection, string tmpFile)
|
||||||
{
|
{
|
||||||
using (var shapes = DisposableCom.Create(selection.ComObject.InlineShapes))
|
using var shapes = DisposableCom.Create(selection.ComObject.InlineShapes);
|
||||||
{
|
|
||||||
var shape = DisposableCom.Create(shapes.ComObject.AddPicture(tmpFile, false, true, Type.Missing));
|
var shape = DisposableCom.Create(shapes.ComObject.AddPicture(tmpFile, false, true, Type.Missing));
|
||||||
// Lock aspect ratio
|
// Lock aspect ratio
|
||||||
if (_officeConfiguration.WordLockAspectRatio)
|
if (_officeConfiguration.WordLockAspectRatio)
|
||||||
|
@ -67,7 +66,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
selection.ComObject.MoveDown(WdUnits.wdLine, 1, Type.Missing);
|
selection.ComObject.MoveDown(WdUnits.wdLine, 1, Type.Missing);
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this to get the running Word application, or create a new instance
|
/// Call this to get the running Word application, or create a new instance
|
||||||
|
@ -113,18 +111,16 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IEnumerable<string> GetWordDocuments()
|
public IEnumerable<string> GetWordDocuments()
|
||||||
{
|
{
|
||||||
using (var wordApplication = GetWordApplication())
|
using var wordApplication = GetWordApplication();
|
||||||
{
|
|
||||||
if (wordApplication == null)
|
if (wordApplication == null)
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
using (var documents = DisposableCom.Create(wordApplication.ComObject.Documents))
|
|
||||||
{
|
using var documents = DisposableCom.Create(wordApplication.ComObject.Documents);
|
||||||
for (int i = 1; i <= documents.ComObject.Count; i++)
|
for (int i = 1; i <= documents.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var document = DisposableCom.Create(documents.ComObject[i]))
|
using var document = DisposableCom.Create(documents.ComObject[i]);
|
||||||
{
|
|
||||||
if (document.ComObject.ReadOnly)
|
if (document.ComObject.ReadOnly)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -136,15 +132,11 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using (var activeWindow = DisposableCom.Create(document.ComObject.ActiveWindow))
|
|
||||||
{
|
using var activeWindow = DisposableCom.Create(document.ComObject.ActiveWindow);
|
||||||
yield return activeWindow.ComObject.Caption;
|
yield return activeWindow.ComObject.Caption;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize static word variables like version
|
/// Initialize static word variables like version
|
||||||
|
@ -177,23 +169,18 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
using (var documents = DisposableCom.Create(wordApplication.ComObject.Documents))
|
|
||||||
{
|
using var documents = DisposableCom.Create(wordApplication.ComObject.Documents);
|
||||||
for (int i = 1; i <= documents.ComObject.Count; i++)
|
for (int i = 1; i <= documents.ComObject.Count; i++)
|
||||||
{
|
{
|
||||||
using (var wordDocument = DisposableCom.Create((_Document)documents.ComObject[i]))
|
using var wordDocument = DisposableCom.Create((_Document)documents.ComObject[i]);
|
||||||
{
|
using var activeWindow = DisposableCom.Create(wordDocument.ComObject.ActiveWindow);
|
||||||
using (var activeWindow = DisposableCom.Create(wordDocument.ComObject.ActiveWindow))
|
|
||||||
{
|
|
||||||
if (activeWindow.ComObject.Caption.StartsWith(wordCaption))
|
if (activeWindow.ComObject.Caption.StartsWith(wordCaption))
|
||||||
{
|
{
|
||||||
return InsertIntoExistingDocument(wordApplication, wordDocument, tmpFile, null, null);
|
return InsertIntoExistingDocument(wordApplication, wordDocument, tmpFile, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,8 +206,8 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(ex);
|
Log.Warn().WriteLine(ex);
|
||||||
}
|
}
|
||||||
using (var selection = DisposableCom.Create(wordApplication.ComObject.Selection))
|
|
||||||
{
|
using var selection = DisposableCom.Create(wordApplication.ComObject.Selection);
|
||||||
if (selection == null)
|
if (selection == null)
|
||||||
{
|
{
|
||||||
Log.Info().WriteLine("No selection to insert {0} into found.", tmpFile);
|
Log.Info().WriteLine("No selection to insert {0} into found.", tmpFile);
|
||||||
|
@ -238,11 +225,9 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var hyperlinks = DisposableCom.Create(wordDocument.ComObject.Hyperlinks))
|
using var hyperlinks = DisposableCom.Create(wordDocument.ComObject.Hyperlinks);
|
||||||
{
|
|
||||||
hyperlinks.ComObject.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
|
hyperlinks.ComObject.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine("Couldn't add hyperlink for image: {0}", e.Message);
|
Log.Warn().WriteLine("Couldn't add hyperlink for image: {0}", e.Message);
|
||||||
|
@ -251,18 +236,12 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var activeWindow = DisposableCom.Create(wordDocument.ComObject.ActiveWindow))
|
using var activeWindow = DisposableCom.Create(wordDocument.ComObject.ActiveWindow);
|
||||||
{
|
|
||||||
activeWindow.ComObject.Activate();
|
activeWindow.ComObject.Activate();
|
||||||
using (var activePane = DisposableCom.Create(activeWindow.ComObject.ActivePane))
|
using var activePane = DisposableCom.Create(activeWindow.ComObject.ActivePane);
|
||||||
{
|
using var view = DisposableCom.Create(activePane.ComObject.View);
|
||||||
using (var view = DisposableCom.Create(activePane.ComObject.View))
|
|
||||||
{
|
|
||||||
view.ComObject.Zoom.Percentage = 100;
|
view.ComObject.Zoom.Percentage = 100;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (e.InnerException != null)
|
if (e.InnerException != null)
|
||||||
|
@ -294,7 +273,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Insert a capture into a new document
|
/// Insert a capture into a new document
|
||||||
|
@ -304,8 +282,7 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
/// <param name="tooltip">string</param>
|
/// <param name="tooltip">string</param>
|
||||||
public void InsertIntoNewDocument(string tmpFile, string address, string tooltip)
|
public void InsertIntoNewDocument(string tmpFile, string address, string tooltip)
|
||||||
{
|
{
|
||||||
using (var wordApplication = GetOrCreateWordApplication())
|
using var wordApplication = GetOrCreateWordApplication();
|
||||||
{
|
|
||||||
if (wordApplication == null)
|
if (wordApplication == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -317,15 +294,12 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
object newTemplate = false;
|
object newTemplate = false;
|
||||||
object documentType = 0;
|
object documentType = 0;
|
||||||
object documentVisible = true;
|
object documentVisible = true;
|
||||||
using (var documents = DisposableCom.Create(wordApplication.ComObject.Documents))
|
using var documents = DisposableCom.Create(wordApplication.ComObject.Documents);
|
||||||
{
|
using var wordDocument = DisposableCom.Create(documents.ComObject.Add(template, newTemplate, documentType, documentVisible));
|
||||||
using (var wordDocument = DisposableCom.Create(documents.ComObject.Add(template, newTemplate, documentType, documentVisible)))
|
|
||||||
{
|
|
||||||
using (var selection = DisposableCom.Create(wordApplication.ComObject.Selection))
|
using (var selection = DisposableCom.Create(wordApplication.ComObject.Selection))
|
||||||
{
|
{
|
||||||
// Add Picture
|
// Add Picture
|
||||||
using (var shape = AddPictureToSelection(selection, tmpFile))
|
using var shape = AddPictureToSelection(selection, tmpFile);
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(address))
|
if (!string.IsNullOrEmpty(address))
|
||||||
{
|
{
|
||||||
object screentip = Type.Missing;
|
object screentip = Type.Missing;
|
||||||
|
@ -335,21 +309,18 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var hyperlinks = DisposableCom.Create(wordDocument.ComObject.Hyperlinks))
|
using var hyperlinks = DisposableCom.Create(wordDocument.ComObject.Hyperlinks);
|
||||||
{
|
|
||||||
using (DisposableCom.Create(hyperlinks.ComObject.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing)))
|
using (DisposableCom.Create(hyperlinks.ComObject.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing)))
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine("Couldn't add hyperlink for image: {0}", e.Message);
|
Log.Warn().WriteLine("Couldn't add hyperlink for image: {0}", e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wordDocument.ComObject.Activate();
|
wordDocument.ComObject.Activate();
|
||||||
|
@ -361,10 +332,8 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var activeWindow = DisposableCom.Create(wordDocument.ComObject.ActiveWindow))
|
using var activeWindow = DisposableCom.Create(wordDocument.ComObject.ActiveWindow);
|
||||||
{
|
|
||||||
activeWindow.ComObject.Activate();
|
activeWindow.ComObject.Activate();
|
||||||
}
|
|
||||||
// ReSharper disable once EmptyGeneralCatchClause
|
// ReSharper disable once EmptyGeneralCatchClause
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -372,9 +341,6 @@ namespace Greenshot.Addon.Office.OfficeExport
|
||||||
Log.Warn().WriteLine(ex);
|
Log.Warn().WriteLine(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if the used version is higher than Office 2003
|
/// Check if the used version is higher than Office 2003
|
||||||
|
|
|
@ -126,12 +126,10 @@ namespace Greenshot.Addon.OneDrive
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this by caching
|
// TODO: Optimize this by caching
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "onedrive.png"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "onedrive.png");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface,
|
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface,
|
||||||
|
@ -188,12 +186,10 @@ namespace Greenshot.Addon.OneDrive
|
||||||
|
|
||||||
if (_oneDriveConfiguration.AfterUploadLinkToClipBoard)
|
if (_oneDriveConfiguration.AfterUploadLinkToClipBoard)
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(response.AbsoluteUri);
|
clipboardAccessToken.SetAsUrl(response.AbsoluteUri);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -227,18 +223,14 @@ namespace Greenshot.Addon.OneDrive
|
||||||
localBehaviour.UploadProgress = percent => { Execute.OnUIThread(() => progress.Report((int)(percent * 100))); };
|
localBehaviour.UploadProgress = percent => { Execute.OnUIThread(() => progress.Report((int)(percent * 100))); };
|
||||||
}
|
}
|
||||||
var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);
|
var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);
|
||||||
using (var imageStream = new MemoryStream())
|
using var imageStream = new MemoryStream();
|
||||||
{
|
|
||||||
surfaceToUpload.WriteToStream(imageStream, CoreConfiguration, _oneDriveConfiguration);
|
surfaceToUpload.WriteToStream(imageStream, CoreConfiguration, _oneDriveConfiguration);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
using (var content = new StreamContent(imageStream))
|
using var content = new StreamContent(imageStream);
|
||||||
{
|
|
||||||
content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(CoreConfiguration, _oneDriveConfiguration));
|
content.Headers.Add("Content-Type", surfaceToUpload.GenerateMimeType(CoreConfiguration, _oneDriveConfiguration));
|
||||||
oauthHttpBehaviour.MakeCurrent();
|
oauthHttpBehaviour.MakeCurrent();
|
||||||
return await uploadUri.PutAsync<OneDriveUploadResponse>(content, token);
|
return await uploadUri.PutAsync<OneDriveUploadResponse>(content, token);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<OneDriveGetLinkResponse> CreateSharableLinkAync(OAuth2Settings oAuth2Settings,
|
private async Task<OneDriveGetLinkResponse> CreateSharableLinkAync(OAuth2Settings oAuth2Settings,
|
||||||
string imageId, OneDriveLinkType oneDriveLinkType)
|
string imageId, OneDriveLinkType oneDriveLinkType)
|
||||||
|
|
|
@ -187,12 +187,10 @@ namespace Greenshot.Addon.Photobucket
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this
|
// TODO: Optimize this
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "photobucket-logo.png"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "photobucket-logo.png");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool IsDynamic => true;
|
public override bool IsDynamic => true;
|
||||||
|
@ -295,8 +293,7 @@ namespace Greenshot.Addon.Photobucket
|
||||||
{
|
{
|
||||||
surfaceToUpload.WriteToStream(imageStream, CoreConfiguration, _photobucketConfiguration);
|
surfaceToUpload.WriteToStream(imageStream, CoreConfiguration, _photobucketConfiguration);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
using (var streamContent = new StreamContent(imageStream))
|
using var streamContent = new StreamContent(imageStream);
|
||||||
{
|
|
||||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue(surfaceToUpload.GenerateMimeType(CoreConfiguration, _photobucketConfiguration));
|
streamContent.Headers.ContentType = new MediaTypeHeaderValue(surfaceToUpload.GenerateMimeType(CoreConfiguration, _photobucketConfiguration));
|
||||||
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
|
||||||
{
|
{
|
||||||
|
@ -318,7 +315,6 @@ namespace Greenshot.Addon.Photobucket
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (responseString == null)
|
if (responseString == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -145,12 +145,10 @@ namespace Greenshot.Addon.Tfs
|
||||||
|
|
||||||
var filename = surface.GenerateFilename(_coreConfiguration, _tfsConfiguration);
|
var filename = surface.GenerateFilename(_coreConfiguration, _tfsConfiguration);
|
||||||
var attachmentUri = apiUri.AppendSegments("wit", "attachments").ExtendQuery("fileName", filename);
|
var attachmentUri = apiUri.AppendSegments("wit", "attachments").ExtendQuery("fileName", filename);
|
||||||
using (var imageStream = new MemoryStream())
|
using var imageStream = new MemoryStream();
|
||||||
{
|
|
||||||
surface.WriteToStream(imageStream, _coreConfiguration, _tfsConfiguration);
|
surface.WriteToStream(imageStream, _coreConfiguration, _tfsConfiguration);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
using (var content = new StreamContent(imageStream))
|
using var content = new StreamContent(imageStream);
|
||||||
{
|
|
||||||
content.SetContentType("application/octet-stream");
|
content.SetContentType("application/octet-stream");
|
||||||
var createAttachmentresult = await client.PostAsync<HttpResponse<CreateAttachmentResult, string>>(attachmentUri, content).ConfigureAwait(false);
|
var createAttachmentresult = await client.PostAsync<HttpResponse<CreateAttachmentResult, string>>(attachmentUri, content).ConfigureAwait(false);
|
||||||
if (createAttachmentresult.HasError)
|
if (createAttachmentresult.HasError)
|
||||||
|
@ -159,8 +157,6 @@ namespace Greenshot.Addon.Tfs
|
||||||
}
|
}
|
||||||
return createAttachmentresult.Response;
|
return createAttachmentresult.Response;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Link the WorkItem and the attachment that was created
|
/// Link the WorkItem and the attachment that was created
|
||||||
|
|
|
@ -165,12 +165,10 @@ namespace Greenshot.Addon.Tfs
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Optimize this by using a cache
|
// TODO: Optimize this by using a cache
|
||||||
using (var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "vsts.png"))
|
using var bitmapStream = _resourceProvider.ResourceAsStream(GetType().Assembly, "vsts.png");
|
||||||
{
|
|
||||||
return BitmapHelper.FromStream(bitmapStream);
|
return BitmapHelper.FromStream(bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
public override async Task<ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
|
||||||
|
@ -224,12 +222,10 @@ namespace Greenshot.Addon.Tfs
|
||||||
|
|
||||||
if (_tfsConfiguration.AfterUploadLinkToClipBoard)
|
if (_tfsConfiguration.AfterUploadLinkToClipBoard)
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
clipboardAccessToken.SetAsUrl(response.AbsoluteUri);
|
clipboardAccessToken.SetAsUrl(response.AbsoluteUri);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,18 +67,13 @@ namespace Greenshot.Addons.Animation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected double EasingValue
|
protected double EasingValue
|
||||||
{
|
{
|
||||||
get
|
get =>
|
||||||
|
EasingMode switch
|
||||||
{
|
{
|
||||||
switch (EasingMode)
|
EasingModes.EaseOut => Easing.EaseOut(CurrentFrameNr / (double) Frames, EasingType),
|
||||||
{
|
EasingModes.EaseInOut => Easing.EaseInOut(CurrentFrameNr / (double) Frames, EasingType),
|
||||||
case EasingModes.EaseOut:
|
_ => Easing.EaseIn(CurrentFrameNr / (double) Frames, EasingType)
|
||||||
return Easing.EaseOut(CurrentFrameNr / (double) Frames, EasingType);
|
};
|
||||||
case EasingModes.EaseInOut:
|
|
||||||
return Easing.EaseInOut(CurrentFrameNr / (double) Frames, EasingType);
|
|
||||||
default:
|
|
||||||
return Easing.EaseIn(CurrentFrameNr / (double) Frames, EasingType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -47,27 +47,18 @@ namespace Greenshot.Addons.Animation
|
||||||
/// <param name="linearStep">double</param>
|
/// <param name="linearStep">double</param>
|
||||||
/// <param name="type">EasingTypes</param>
|
/// <param name="type">EasingTypes</param>
|
||||||
/// <returns>double</returns>
|
/// <returns>double</returns>
|
||||||
public static double EaseIn(double linearStep, EasingTypes type)
|
public static double EaseIn(double linearStep, EasingTypes type) =>
|
||||||
|
type switch
|
||||||
{
|
{
|
||||||
switch (type)
|
EasingTypes.Step => (linearStep < 0.5 ? 0 : 1),
|
||||||
{
|
EasingTypes.Linear => linearStep,
|
||||||
case EasingTypes.Step:
|
EasingTypes.Sine => EaseSine.EaseIn(linearStep),
|
||||||
return linearStep < 0.5 ? 0 : 1;
|
EasingTypes.Quadratic => EasePower.EaseIn(linearStep, 2),
|
||||||
case EasingTypes.Linear:
|
EasingTypes.Cubic => EasePower.EaseIn(linearStep, 3),
|
||||||
return linearStep;
|
EasingTypes.Quartic => EasePower.EaseIn(linearStep, 4),
|
||||||
case EasingTypes.Sine:
|
EasingTypes.Quintic => EasePower.EaseIn(linearStep, 5),
|
||||||
return EaseSine.EaseIn(linearStep);
|
_ => throw new NotImplementedException()
|
||||||
case EasingTypes.Quadratic:
|
};
|
||||||
return EasePower.EaseIn(linearStep, 2);
|
|
||||||
case EasingTypes.Cubic:
|
|
||||||
return EasePower.EaseIn(linearStep, 3);
|
|
||||||
case EasingTypes.Quartic:
|
|
||||||
return EasePower.EaseIn(linearStep, 4);
|
|
||||||
case EasingTypes.Quintic:
|
|
||||||
return EasePower.EaseIn(linearStep, 5);
|
|
||||||
}
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply ease in-out
|
/// Apply ease in-out
|
||||||
|
@ -87,27 +78,18 @@ namespace Greenshot.Addons.Animation
|
||||||
/// <param name="linearStep">double</param>
|
/// <param name="linearStep">double</param>
|
||||||
/// <param name="type">EasingTypes</param>
|
/// <param name="type">EasingTypes</param>
|
||||||
/// <returns>double</returns>
|
/// <returns>double</returns>
|
||||||
public static double EaseInOut(double linearStep, EasingTypes type)
|
public static double EaseInOut(double linearStep, EasingTypes type) =>
|
||||||
|
type switch
|
||||||
{
|
{
|
||||||
switch (type)
|
EasingTypes.Step => (linearStep < 0.5 ? 0 : 1),
|
||||||
{
|
EasingTypes.Linear => linearStep,
|
||||||
case EasingTypes.Step:
|
EasingTypes.Sine => EaseSine.EaseInOut(linearStep),
|
||||||
return linearStep < 0.5 ? 0 : 1;
|
EasingTypes.Quadratic => EasePower.EaseInOut(linearStep, 2),
|
||||||
case EasingTypes.Linear:
|
EasingTypes.Cubic => EasePower.EaseInOut(linearStep, 3),
|
||||||
return linearStep;
|
EasingTypes.Quartic => EasePower.EaseInOut(linearStep, 4),
|
||||||
case EasingTypes.Sine:
|
EasingTypes.Quintic => EasePower.EaseInOut(linearStep, 5),
|
||||||
return EaseSine.EaseInOut(linearStep);
|
_ => throw new NotImplementedException()
|
||||||
case EasingTypes.Quadratic:
|
};
|
||||||
return EasePower.EaseInOut(linearStep, 2);
|
|
||||||
case EasingTypes.Cubic:
|
|
||||||
return EasePower.EaseInOut(linearStep, 3);
|
|
||||||
case EasingTypes.Quartic:
|
|
||||||
return EasePower.EaseInOut(linearStep, 4);
|
|
||||||
case EasingTypes.Quintic:
|
|
||||||
return EasePower.EaseInOut(linearStep, 5);
|
|
||||||
}
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply easy out
|
/// Apply easy out
|
||||||
|
@ -115,26 +97,17 @@ namespace Greenshot.Addons.Animation
|
||||||
/// <param name="linearStep">double</param>
|
/// <param name="linearStep">double</param>
|
||||||
/// <param name="type">EasingTypes</param>
|
/// <param name="type">EasingTypes</param>
|
||||||
/// <returns>double</returns>
|
/// <returns>double</returns>
|
||||||
public static double EaseOut(double linearStep, EasingTypes type)
|
public static double EaseOut(double linearStep, EasingTypes type) =>
|
||||||
|
type switch
|
||||||
{
|
{
|
||||||
switch (type)
|
EasingTypes.Step => (linearStep < 0.5 ? 0 : 1),
|
||||||
{
|
EasingTypes.Linear => linearStep,
|
||||||
case EasingTypes.Step:
|
EasingTypes.Sine => EaseSine.EaseOut(linearStep),
|
||||||
return linearStep < 0.5 ? 0 : 1;
|
EasingTypes.Quadratic => EasePower.EaseOut(linearStep, 2),
|
||||||
case EasingTypes.Linear:
|
EasingTypes.Cubic => EasePower.EaseOut(linearStep, 3),
|
||||||
return linearStep;
|
EasingTypes.Quartic => EasePower.EaseOut(linearStep, 4),
|
||||||
case EasingTypes.Sine:
|
EasingTypes.Quintic => EasePower.EaseOut(linearStep, 5),
|
||||||
return EaseSine.EaseOut(linearStep);
|
_ => throw new NotImplementedException()
|
||||||
case EasingTypes.Quadratic:
|
};
|
||||||
return EasePower.EaseOut(linearStep, 2);
|
|
||||||
case EasingTypes.Cubic:
|
|
||||||
return EasePower.EaseOut(linearStep, 3);
|
|
||||||
case EasingTypes.Quartic:
|
|
||||||
return EasePower.EaseOut(linearStep, 4);
|
|
||||||
case EasingTypes.Quintic:
|
|
||||||
return EasePower.EaseOut(linearStep, 5);
|
|
||||||
}
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -83,11 +83,9 @@ namespace Greenshot.Addons.Controls
|
||||||
if (_vRefresh == 0)
|
if (_vRefresh == 0)
|
||||||
{
|
{
|
||||||
// get te hDC of the desktop to get the VREFRESH
|
// get te hDC of the desktop to get the VREFRESH
|
||||||
using (var desktopHandle = SafeWindowDcHandle.FromDesktop())
|
using var desktopHandle = SafeWindowDcHandle.FromDesktop();
|
||||||
{
|
|
||||||
_vRefresh = Gdi32Api.GetDeviceCaps(desktopHandle, DeviceCaps.VREFRESH);
|
_vRefresh = Gdi32Api.GetDeviceCaps(desktopHandle, DeviceCaps.VREFRESH);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// A vertical refresh rate value of 0 or 1 represents the display hardware's default refresh rate.
|
// A vertical refresh rate value of 0 or 1 represents the display hardware's default refresh rate.
|
||||||
// As there is currently no know way to get the default, we guess it.
|
// As there is currently no know way to get the default, we guess it.
|
||||||
if (_vRefresh <= 1)
|
if (_vRefresh <= 1)
|
||||||
|
|
|
@ -102,8 +102,7 @@ namespace Greenshot.Addons.Controls
|
||||||
/// <returns>Color at the specified screenCoordinates</returns>
|
/// <returns>Color at the specified screenCoordinates</returns>
|
||||||
private static Color GetPixelColor(Point screenCoordinates)
|
private static Color GetPixelColor(Point screenCoordinates)
|
||||||
{
|
{
|
||||||
using (var screenDc = SafeWindowDcHandle.FromDesktop())
|
using var screenDc = SafeWindowDcHandle.FromDesktop();
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var pixel = Gdi32Api.GetPixel(screenDc, screenCoordinates.X, screenCoordinates.Y);
|
var pixel = Gdi32Api.GetPixel(screenDc, screenCoordinates.X, screenCoordinates.Y);
|
||||||
|
@ -117,4 +116,3 @@ namespace Greenshot.Addons.Controls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -132,6 +132,7 @@ namespace Greenshot.Addons.Core
|
||||||
_safeDibSectionHandle.Dispose();
|
_safeDibSectionHandle.Dispose();
|
||||||
_safeCompatibleDcHandle.Dispose();
|
_safeCompatibleDcHandle.Dispose();
|
||||||
_desktopDcHandle.Dispose();
|
_desktopDcHandle.Dispose();
|
||||||
|
_bitmap.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,9 +122,8 @@ EndSelection:<<<<<<<4
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
User32Api.GetWindowThreadProcessId(hWnd, out var pid);
|
User32Api.GetWindowThreadProcessId(hWnd, out var pid);
|
||||||
using (var me = Process.GetCurrentProcess())
|
using var me = Process.GetCurrentProcess();
|
||||||
using (var ownerProcess = Process.GetProcessById(pid))
|
using var ownerProcess = Process.GetProcessById(pid);
|
||||||
{
|
|
||||||
// Exclude myself
|
// Exclude myself
|
||||||
if (me.Id != ownerProcess.Id)
|
if (me.Id != ownerProcess.Id)
|
||||||
{
|
{
|
||||||
|
@ -141,7 +140,6 @@ EndSelection:<<<<<<<4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(e, "Non critical error: Couldn't get clipboard process, trying to use the title.");
|
Log.Warn().WriteLine(e, "Non critical error: Couldn't get clipboard process, trying to use the title.");
|
||||||
|
@ -483,8 +481,7 @@ EndSelection:<<<<<<<4
|
||||||
var fileHeader = BitmapFileHeader.Create(infoHeader);
|
var fileHeader = BitmapFileHeader.Create(infoHeader);
|
||||||
var fileHeaderBytes = BinaryStructHelper.ToByteArray(fileHeader);
|
var fileHeaderBytes = BinaryStructHelper.ToByteArray(fileHeader);
|
||||||
|
|
||||||
using (var bitmapStream = new MemoryStream())
|
using var bitmapStream = new MemoryStream();
|
||||||
{
|
|
||||||
bitmapStream.Write(fileHeaderBytes, 0, fileHeaderSize);
|
bitmapStream.Write(fileHeaderBytes, 0, fileHeaderSize);
|
||||||
bitmapStream.Write(dibBuffer, 0, dibBuffer.Length);
|
bitmapStream.Write(dibBuffer, 0, dibBuffer.Length);
|
||||||
bitmapStream.Seek(0, SeekOrigin.Begin);
|
bitmapStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
@ -494,7 +491,6 @@ EndSelection:<<<<<<<4
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log.Info().WriteLine("Using special DIBV5 / Format17 format reader");
|
Log.Info().WriteLine("Using special DIBV5 / Format17 format reader");
|
||||||
|
|
|
@ -327,7 +327,8 @@ namespace Greenshot.Addons.Core.Credentials
|
||||||
info.pszMessageText = Message;
|
info.pszMessageText = Message;
|
||||||
if (Banner != null)
|
if (Banner != null)
|
||||||
{
|
{
|
||||||
info.hbmBanner = new Bitmap(Banner, ValidBannerWidth, ValidBannerHeight).GetHbitmap();
|
using var bitmap = new Bitmap(Banner, ValidBannerWidth, ValidBannerHeight);
|
||||||
|
info.hbmBanner = bitmap.GetHbitmap();
|
||||||
}
|
}
|
||||||
info.cbSize = Marshal.SizeOf(info);
|
info.cbSize = Marshal.SizeOf(info);
|
||||||
return info;
|
return info;
|
||||||
|
@ -380,34 +381,19 @@ namespace Greenshot.Addons.Core.Credentials
|
||||||
|
|
||||||
/// <summary>Returns a DialogResult from the specified code.</summary>
|
/// <summary>Returns a DialogResult from the specified code.</summary>
|
||||||
/// <param name="code">The credential return code.</param>
|
/// <param name="code">The credential return code.</param>
|
||||||
private DialogResult GetDialogResult(CredUiReturnCodes code)
|
private DialogResult GetDialogResult(CredUiReturnCodes code) =>
|
||||||
|
code switch
|
||||||
{
|
{
|
||||||
DialogResult result;
|
CredUiReturnCodes.NoError => DialogResult.OK,
|
||||||
switch (code)
|
CredUiReturnCodes.ErrorCancelled => DialogResult.Cancel,
|
||||||
{
|
CredUiReturnCodes.ErrorNoSuchLogonSession => throw new ApplicationException("No such logon session."),
|
||||||
case CredUiReturnCodes.NoError:
|
CredUiReturnCodes.ErrorNotFound => throw new ApplicationException("Not found."),
|
||||||
result = DialogResult.OK;
|
CredUiReturnCodes.ErrorInvalidAccountName => throw new ApplicationException("Invalid account name."),
|
||||||
break;
|
CredUiReturnCodes.ErrorInsufficientBuffer => throw new ApplicationException("Insufficient buffer."),
|
||||||
case CredUiReturnCodes.ErrorCancelled:
|
CredUiReturnCodes.ErrorInvalidParameter => throw new ApplicationException("Invalid parameter."),
|
||||||
result = DialogResult.Cancel;
|
CredUiReturnCodes.ErrorInvalidFlags => throw new ApplicationException("Invalid flags."),
|
||||||
break;
|
_ => throw new ApplicationException("Unknown credential result encountered.")
|
||||||
case CredUiReturnCodes.ErrorNoSuchLogonSession:
|
};
|
||||||
throw new ApplicationException("No such logon session.");
|
|
||||||
case CredUiReturnCodes.ErrorNotFound:
|
|
||||||
throw new ApplicationException("Not found.");
|
|
||||||
case CredUiReturnCodes.ErrorInvalidAccountName:
|
|
||||||
throw new ApplicationException("Invalid account name.");
|
|
||||||
case CredUiReturnCodes.ErrorInsufficientBuffer:
|
|
||||||
throw new ApplicationException("Insufficient buffer.");
|
|
||||||
case CredUiReturnCodes.ErrorInvalidParameter:
|
|
||||||
throw new ApplicationException("Invalid parameter.");
|
|
||||||
case CredUiReturnCodes.ErrorInvalidFlags:
|
|
||||||
throw new ApplicationException("Invalid flags.");
|
|
||||||
default:
|
|
||||||
throw new ApplicationException("Unknown credential result encountered.");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// http://www.pinvoke.net/default.aspx/credui.CredUIPromptForCredentialsW
|
/// http://www.pinvoke.net/default.aspx/credui.CredUIPromptForCredentialsW
|
||||||
|
|
|
@ -57,11 +57,9 @@ namespace Greenshot.Addons.Core
|
||||||
/// <returns>bool</returns>
|
/// <returns>bool</returns>
|
||||||
public static bool HasMapi()
|
public static bool HasMapi()
|
||||||
{
|
{
|
||||||
using (var key = Registry.LocalMachine.OpenSubKey(MapiLocationKey, false))
|
using var key = Registry.LocalMachine.OpenSubKey(MapiLocationKey, false);
|
||||||
{
|
|
||||||
return key != null && "1".Equals(key.GetValue(MapiKey, "0"));
|
return key != null && "1".Equals(key.GetValue(MapiKey, "0"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the path of Outlook from the registry
|
/// Get the path of Outlook from the registry
|
||||||
|
|
|
@ -67,13 +67,11 @@ namespace Greenshot.Addons.Core
|
||||||
UseShellExecute = true
|
UseShellExecute = true
|
||||||
};
|
};
|
||||||
// Start the explorer process and select the file
|
// Start the explorer process and select the file
|
||||||
using (var explorer = Process.Start(processStartInfo))
|
using var explorer = Process.Start(processStartInfo);
|
||||||
{
|
|
||||||
explorer?.WaitForInputIdle(500);
|
explorer?.WaitForInputIdle(500);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Make sure we show what we tried to open in the exception
|
// Make sure we show what we tried to open in the exception
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace Greenshot.Addons.Core
|
||||||
// Set the text
|
// Set the text
|
||||||
var byteString = Encoding.ASCII.GetBytes(text + " ");
|
var byteString = Encoding.ASCII.GetBytes(text + " ");
|
||||||
// Set Zero byte for String end.
|
// Set Zero byte for String end.
|
||||||
byteString[byteString.Length - 1] = 0;
|
byteString[^1] = 0;
|
||||||
propertyItem.Value = byteString;
|
propertyItem.Value = byteString;
|
||||||
propertyItem.Len = text.Length + 1;
|
propertyItem.Len = text.Length + 1;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ namespace Greenshot.Addons.Core
|
||||||
if (CoreConfiguration.OutputFilePromptQuality)
|
if (CoreConfiguration.OutputFilePromptQuality)
|
||||||
{
|
{
|
||||||
// TODO: Use factory
|
// TODO: Use factory
|
||||||
var qualityDialog = new QualityDialog(outputSettings, CoreConfiguration, GreenshotLanguage);
|
using var qualityDialog = new QualityDialog(outputSettings, CoreConfiguration, GreenshotLanguage);
|
||||||
qualityDialog.ShowDialog();
|
qualityDialog.ShowDialog();
|
||||||
}
|
}
|
||||||
// TODO: For now we always overwrite, should be changed
|
// TODO: For now we always overwrite, should be changed
|
||||||
|
@ -310,24 +310,18 @@ namespace Greenshot.Addons.Core
|
||||||
var imageStream = new MemoryStream();
|
var imageStream = new MemoryStream();
|
||||||
if (bitmap.Width == size && bitmap.Height == size)
|
if (bitmap.Width == size && bitmap.Height == size)
|
||||||
{
|
{
|
||||||
using (var clonedImage = bitmap.CloneBitmap(PixelFormat.Format32bppArgb))
|
using var clonedImage = bitmap.CloneBitmap(PixelFormat.Format32bppArgb);
|
||||||
{
|
|
||||||
clonedImage.NativeBitmap.Save(imageStream, ImageFormat.Png);
|
clonedImage.NativeBitmap.Save(imageStream, ImageFormat.Png);
|
||||||
imageSizes.Add(new Size(size, size));
|
imageSizes.Add(new Size(size, size));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Resize to the specified size, first make sure the image is 32bpp
|
// Resize to the specified size, first make sure the image is 32bpp
|
||||||
using (var clonedImage = bitmap.CloneBitmap(PixelFormat.Format32bppArgb))
|
using var clonedImage = bitmap.CloneBitmap(PixelFormat.Format32bppArgb);
|
||||||
{
|
using var resizedImage = clonedImage.Resize(true, true, Color.Empty, size, size, null);
|
||||||
using (var resizedImage = clonedImage.Resize(true, true, Color.Empty, size, size, null))
|
|
||||||
{
|
|
||||||
resizedImage.NativeBitmap.Save(imageStream, ImageFormat.Png);
|
resizedImage.NativeBitmap.Save(imageStream, ImageFormat.Png);
|
||||||
imageSizes.Add(resizedImage.Size);
|
imageSizes.Add(resizedImage.Size);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
imageStream.Seek(0, SeekOrigin.Begin);
|
imageStream.Seek(0, SeekOrigin.Begin);
|
||||||
encodedImages.Add(imageStream);
|
encodedImages.Add(imageStream);
|
||||||
|
@ -395,13 +389,11 @@ namespace Greenshot.Addons.Core
|
||||||
Log.Info().WriteLine("Greenshot file format: {0}", greenshotMarker);
|
Log.Info().WriteLine("Greenshot file format: {0}", greenshotMarker);
|
||||||
const int filesizeLocation = 8 + markerSize;
|
const int filesizeLocation = 8 + markerSize;
|
||||||
surfaceFileStream.Seek(-filesizeLocation, SeekOrigin.End);
|
surfaceFileStream.Seek(-filesizeLocation, SeekOrigin.End);
|
||||||
using (var reader = new BinaryReader(surfaceFileStream))
|
using var reader = new BinaryReader(surfaceFileStream);
|
||||||
{
|
|
||||||
var bytesWritten = reader.ReadInt64();
|
var bytesWritten = reader.ReadInt64();
|
||||||
surfaceFileStream.Seek(-(bytesWritten + filesizeLocation), SeekOrigin.End);
|
surfaceFileStream.Seek(-(bytesWritten + filesizeLocation), SeekOrigin.End);
|
||||||
returnSurface.LoadElementsFromStream(surfaceFileStream);
|
returnSurface.LoadElementsFromStream(surfaceFileStream);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (fileImage == null)
|
if (fileImage == null)
|
||||||
{
|
{
|
||||||
return returnSurface;
|
return returnSurface;
|
||||||
|
@ -567,11 +559,9 @@ namespace Greenshot.Addons.Core
|
||||||
// Output the surface elements, size and marker to the stream
|
// Output the surface elements, size and marker to the stream
|
||||||
if (outputSettings.Format == OutputFormats.greenshot)
|
if (outputSettings.Format == OutputFormats.greenshot)
|
||||||
{
|
{
|
||||||
using (var tmpStream = new MemoryStream())
|
using var tmpStream = new MemoryStream();
|
||||||
{
|
|
||||||
var bytesWritten = surface.SaveElementsToStream(tmpStream);
|
var bytesWritten = surface.SaveElementsToStream(tmpStream);
|
||||||
using (var writer = new BinaryWriter(tmpStream))
|
using var writer = new BinaryWriter(tmpStream);
|
||||||
{
|
|
||||||
writer.Write(bytesWritten);
|
writer.Write(bytesWritten);
|
||||||
var v = Assembly.GetExecutingAssembly().GetName().Version;
|
var v = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
var marker = Encoding.ASCII.GetBytes($"Greenshot{v.Major:00}.{v.Minor:00}");
|
var marker = Encoding.ASCII.GetBytes($"Greenshot{v.Major:00}.{v.Minor:00}");
|
||||||
|
@ -579,8 +569,6 @@ namespace Greenshot.Addons.Core
|
||||||
tmpStream.WriteTo(stream);
|
tmpStream.WriteTo(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
memoryStream?.Dispose();
|
memoryStream?.Dispose();
|
||||||
|
@ -630,8 +618,7 @@ namespace Greenshot.Addons.Core
|
||||||
RedirectStandardError = true,
|
RedirectStandardError = true,
|
||||||
UseShellExecute = true
|
UseShellExecute = true
|
||||||
};
|
};
|
||||||
using (var process = Process.Start(processStartInfo))
|
using var process = Process.Start(processStartInfo);
|
||||||
{
|
|
||||||
if (process != null)
|
if (process != null)
|
||||||
{
|
{
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
|
@ -651,7 +638,6 @@ namespace Greenshot.Addons.Core
|
||||||
Log.Error().WriteLine("Error: {0}", process.StandardError.ReadToEnd());
|
Log.Error().WriteLine("Error: {0}", process.StandardError.ReadToEnd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error().WriteLine(e, "Error while processing PNG image: ");
|
Log.Error().WriteLine(e, "Error while processing PNG image: ");
|
||||||
|
@ -722,8 +708,7 @@ namespace Greenshot.Addons.Core
|
||||||
var isAlpha = Image.IsAlphaPixelFormat(bitmapToSave.PixelFormat);
|
var isAlpha = Image.IsAlphaPixelFormat(bitmapToSave.PixelFormat);
|
||||||
if (outputSettings.ReduceColors || !isAlpha && CoreConfiguration.OutputFileAutoReduceColors)
|
if (outputSettings.ReduceColors || !isAlpha && CoreConfiguration.OutputFileAutoReduceColors)
|
||||||
{
|
{
|
||||||
using (var quantizer = new WuQuantizer(bitmapToSave))
|
using var quantizer = new WuQuantizer(bitmapToSave);
|
||||||
{
|
|
||||||
var colorCount = quantizer.GetColorCount();
|
var colorCount = quantizer.GetColorCount();
|
||||||
Log.Info().WriteLine("Image with format {0} has {1} colors", bitmapToSave.PixelFormat, colorCount);
|
Log.Info().WriteLine("Image with format {0} has {1} colors", bitmapToSave.PixelFormat, colorCount);
|
||||||
if (!outputSettings.ReduceColors && colorCount >= 256)
|
if (!outputSettings.ReduceColors && colorCount >= 256)
|
||||||
|
@ -747,7 +732,6 @@ namespace Greenshot.Addons.Core
|
||||||
Log.Warn().WriteLine(e, "Error occurred while Quantizing the image, ignoring and using original. Error: ");
|
Log.Warn().WriteLine(e, "Error occurred while Quantizing the image, ignoring and using original. Error: ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (isAlpha && !outputSettings.ReduceColors)
|
else if (isAlpha && !outputSettings.ReduceColors)
|
||||||
{
|
{
|
||||||
Log.Info().WriteLine("Skipping 'optional' color reduction as the image has alpha");
|
Log.Info().WriteLine("Skipping 'optional' color reduction as the image has alpha");
|
||||||
|
@ -838,14 +822,12 @@ namespace Greenshot.Addons.Core
|
||||||
// TODO: This should not be done here, remove this!!
|
// TODO: This should not be done here, remove this!!
|
||||||
if (copyPathToClipboard)
|
if (copyPathToClipboard)
|
||||||
{
|
{
|
||||||
using (var clipboardAccessToken = ClipboardNative.Access())
|
using var clipboardAccessToken = ClipboardNative.Access();
|
||||||
{
|
|
||||||
clipboardAccessToken.ClearContents();
|
clipboardAccessToken.ClearContents();
|
||||||
// TODO: File??
|
// TODO: File??
|
||||||
clipboardAccessToken.SetAsUnicodeString(fullPath);
|
clipboardAccessToken.SetAsUnicodeString(fullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the OutputFormats for a filename
|
/// Get the OutputFormats for a filename
|
||||||
|
|
|
@ -187,8 +187,7 @@ namespace Greenshot.Addons.Core
|
||||||
{
|
{
|
||||||
// Assume using it's own location
|
// Assume using it's own location
|
||||||
formLocation = windowRectangle.Location;
|
formLocation = windowRectangle.Location;
|
||||||
using (var workingArea = new Region(Screen.PrimaryScreen.Bounds))
|
using var workingArea = new Region(Screen.PrimaryScreen.Bounds);
|
||||||
{
|
|
||||||
// Find the screen where the window is and check if it fits
|
// Find the screen where the window is and check if it fits
|
||||||
foreach (var screen in Screen.AllScreens)
|
foreach (var screen in Screen.AllScreens)
|
||||||
{
|
{
|
||||||
|
@ -218,7 +217,6 @@ namespace Greenshot.Addons.Core
|
||||||
doesCaptureFit = true;
|
doesCaptureFit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (!WindowsVersion.IsWindows8OrLater)
|
else if (!WindowsVersion.IsWindows8OrLater)
|
||||||
{
|
{
|
||||||
//GetClientRect(out windowRectangle);
|
//GetClientRect(out windowRectangle);
|
||||||
|
@ -251,8 +249,7 @@ namespace Greenshot.Addons.Core
|
||||||
if (!doesCaptureFit)
|
if (!doesCaptureFit)
|
||||||
{
|
{
|
||||||
// if GDI is allowed.. (a screenshot won't be better than we comes if we continue)
|
// if GDI is allowed.. (a screenshot won't be better than we comes if we continue)
|
||||||
using (var thisWindowProcess = Process.GetProcessById(interopWindow.GetProcessId()))
|
using var thisWindowProcess = Process.GetProcessById(interopWindow.GetProcessId());
|
||||||
{
|
|
||||||
if (!interopWindow.IsApp() && WindowCapture.IsGdiAllowed(thisWindowProcess))
|
if (!interopWindow.IsApp() && WindowCapture.IsGdiAllowed(thisWindowProcess))
|
||||||
{
|
{
|
||||||
// we return null which causes the capturing code to try another method.
|
// we return null which causes the capturing code to try another method.
|
||||||
|
@ -261,7 +258,6 @@ namespace Greenshot.Addons.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Prepare the displaying of the Thumbnail
|
// Prepare the displaying of the Thumbnail
|
||||||
var props = new DwmThumbnailProperties
|
var props = new DwmThumbnailProperties
|
||||||
{
|
{
|
||||||
|
@ -289,8 +285,7 @@ namespace Greenshot.Addons.Core
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var whiteBitmap = WindowCapture.CaptureRectangle(captureRectangle))
|
using var whiteBitmap = WindowCapture.CaptureRectangle(captureRectangle);
|
||||||
{
|
|
||||||
// Apply a white color
|
// Apply a white color
|
||||||
tempForm.BackColor = Color.Black;
|
tempForm.BackColor = Color.Black;
|
||||||
// Make sure everything is visible
|
// Make sure everything is visible
|
||||||
|
@ -303,12 +298,9 @@ namespace Greenshot.Addons.Core
|
||||||
}
|
}
|
||||||
// Make sure all changes are processed and visible
|
// Make sure all changes are processed and visible
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
using (var blackBitmap = WindowCapture.CaptureRectangle(captureRectangle))
|
using var blackBitmap = WindowCapture.CaptureRectangle(captureRectangle);
|
||||||
{
|
|
||||||
capturedBitmap = ApplyTransparency(blackBitmap, whiteBitmap);
|
capturedBitmap = ApplyTransparency(blackBitmap, whiteBitmap);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(e, "Exception: ");
|
Log.Warn().WriteLine(e, "Exception: ");
|
||||||
|
@ -400,8 +392,7 @@ namespace Greenshot.Addons.Core
|
||||||
/// <param name="image">The bitmap to remove the corners from.</param>
|
/// <param name="image">The bitmap to remove the corners from.</param>
|
||||||
private static void RemoveCorners(IBitmapWithNativeSupport image)
|
private static void RemoveCorners(IBitmapWithNativeSupport image)
|
||||||
{
|
{
|
||||||
using (var fastBitmap = FastBitmapFactory.Create(image))
|
using var fastBitmap = FastBitmapFactory.Create(image);
|
||||||
{
|
|
||||||
for (var y = 0; y < CoreConfiguration.WindowCornerCutShape.Count; y++)
|
for (var y = 0; y < CoreConfiguration.WindowCornerCutShape.Count; y++)
|
||||||
{
|
{
|
||||||
for (var x = 0; x < CoreConfiguration.WindowCornerCutShape[y]; x++)
|
for (var x = 0; x < CoreConfiguration.WindowCornerCutShape[y]; x++)
|
||||||
|
@ -413,7 +404,6 @@ namespace Greenshot.Addons.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply transparency by comparing a transparent capture with a black and white background
|
/// Apply transparency by comparing a transparent capture with a black and white background
|
||||||
|
@ -425,13 +415,11 @@ namespace Greenshot.Addons.Core
|
||||||
/// <returns>Bitmap with transparency</returns>
|
/// <returns>Bitmap with transparency</returns>
|
||||||
private static IBitmapWithNativeSupport ApplyTransparency(IBitmapWithNativeSupport blackBitmap, IBitmapWithNativeSupport whiteBitmap)
|
private static IBitmapWithNativeSupport ApplyTransparency(IBitmapWithNativeSupport blackBitmap, IBitmapWithNativeSupport whiteBitmap)
|
||||||
{
|
{
|
||||||
using (var targetBuffer = FastBitmapFactory.CreateEmpty(blackBitmap.Size, PixelFormat.Format32bppArgb, Color.Transparent))
|
using var targetBuffer = FastBitmapFactory.CreateEmpty(blackBitmap.Size, PixelFormat.Format32bppArgb, Color.Transparent);
|
||||||
{
|
|
||||||
targetBuffer.SetResolution(blackBitmap.HorizontalResolution, blackBitmap.VerticalResolution);
|
targetBuffer.SetResolution(blackBitmap.HorizontalResolution, blackBitmap.VerticalResolution);
|
||||||
using (var blackBuffer = FastBitmapFactory.Create(blackBitmap))
|
using (var blackBuffer = FastBitmapFactory.Create(blackBitmap))
|
||||||
{
|
{
|
||||||
using (var whiteBuffer = FastBitmapFactory.Create(whiteBitmap))
|
using var whiteBuffer = FastBitmapFactory.Create(whiteBitmap);
|
||||||
{
|
|
||||||
for (var y = 0; y < blackBuffer.Height; y++)
|
for (var y = 0; y < blackBuffer.Height; y++)
|
||||||
{
|
{
|
||||||
for (var x = 0; x < blackBuffer.Width; x++)
|
for (var x = 0; x < blackBuffer.Width; x++)
|
||||||
|
@ -466,9 +454,7 @@ namespace Greenshot.Addons.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return targetBuffer.UnlockAndReturnBitmap();
|
return targetBuffer.UnlockAndReturnBitmap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -52,13 +52,11 @@ namespace Greenshot.Addons.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
IFormatter formatter = new BinaryFormatter();
|
IFormatter formatter = new BinaryFormatter();
|
||||||
using (var stream = new MemoryStream())
|
using var stream = new MemoryStream();
|
||||||
{
|
|
||||||
formatter.Serialize(stream, source);
|
formatter.Serialize(stream, source);
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
return (T) formatter.Deserialize(stream);
|
return (T) formatter.Deserialize(stream);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clone the content from source to destination
|
/// Clone the content from source to destination
|
||||||
|
|
|
@ -116,12 +116,10 @@ namespace Greenshot.Addons.Core
|
||||||
// Set the location
|
// Set the location
|
||||||
capture.CursorLocation = new NativePoint(x, y);
|
capture.CursorLocation = new NativePoint(x, y);
|
||||||
|
|
||||||
using (var icon = Icon.FromHandle(safeIcon.DangerousGetHandle()))
|
using var icon = Icon.FromHandle(safeIcon.DangerousGetHandle());
|
||||||
{
|
|
||||||
capture.Cursor = icon;
|
capture.Cursor = icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return capture;
|
return capture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,8 +303,7 @@ namespace Greenshot.Addons.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a device context we can copy to
|
// create a device context we can copy to
|
||||||
using (var safeCompatibleDcHandle = Gdi32Api.CreateCompatibleDC(desktopDcHandle))
|
using var safeCompatibleDcHandle = Gdi32Api.CreateCompatibleDC(desktopDcHandle);
|
||||||
{
|
|
||||||
// Check if the device context is there, if not throw an error with as much info as possible!
|
// Check if the device context is there, if not throw an error with as much info as possible!
|
||||||
if (safeCompatibleDcHandle.IsInvalid)
|
if (safeCompatibleDcHandle.IsInvalid)
|
||||||
{
|
{
|
||||||
|
@ -324,8 +321,7 @@ namespace Greenshot.Addons.Core
|
||||||
|
|
||||||
// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
|
// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
|
||||||
// the returned (out) IntPtr _ is not used for our purposes. It returns a pointer to the raw bits that make up the bitmap.
|
// the returned (out) IntPtr _ is not used for our purposes. It returns a pointer to the raw bits that make up the bitmap.
|
||||||
using (var safeDibSectionHandle = Gdi32Api.CreateDIBSection(desktopDcHandle, ref bmi, DibColors.PalColors, out _, IntPtr.Zero, 0))
|
using var safeDibSectionHandle = Gdi32Api.CreateDIBSection(desktopDcHandle, ref bmi, DibColors.PalColors, out _, IntPtr.Zero, 0);
|
||||||
{
|
|
||||||
if (safeDibSectionHandle.IsInvalid)
|
if (safeDibSectionHandle.IsInvalid)
|
||||||
{
|
{
|
||||||
// Get Exception before the error is lost
|
// Get Exception before the error is lost
|
||||||
|
@ -371,16 +367,13 @@ namespace Greenshot.Addons.Core
|
||||||
captureRegion.Exclude(screen.Bounds);
|
captureRegion.Exclude(screen.Bounds);
|
||||||
}
|
}
|
||||||
// If the region is not empty, we have "offscreenContent"
|
// If the region is not empty, we have "offscreenContent"
|
||||||
using (var screenGraphics = Graphics.FromHwnd(User32Api.GetDesktopWindow()))
|
using var screenGraphics = Graphics.FromHwnd(User32Api.GetDesktopWindow());
|
||||||
{
|
|
||||||
offscreenContent = !captureRegion.IsEmpty(screenGraphics);
|
offscreenContent = !captureRegion.IsEmpty(screenGraphics);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Check if we need to have a transparent background, needed for offscreen content
|
// Check if we need to have a transparent background, needed for offscreen content
|
||||||
if (offscreenContent)
|
if (offscreenContent)
|
||||||
{
|
{
|
||||||
using (var tmpBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle()))
|
using var tmpBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle());
|
||||||
{
|
|
||||||
// Create a new bitmap which has a transparent background
|
// Create a new bitmap which has a transparent background
|
||||||
var returnBitmap = new UnmanagedBitmap<Bgra32>(tmpBitmap.Width, tmpBitmap.Height, tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution);
|
var returnBitmap = new UnmanagedBitmap<Bgra32>(tmpBitmap.Width, tmpBitmap.Height, tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution);
|
||||||
returnBitmap.Span.Fill(Color.Transparent.FromColorWithAlpha());
|
returnBitmap.Span.Fill(Color.Transparent.FromColorWithAlpha());
|
||||||
|
@ -399,7 +392,6 @@ namespace Greenshot.Addons.Core
|
||||||
|
|
||||||
return returnBitmap;
|
return returnBitmap;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// All screens, which are inside the capture, are of equal size
|
// All screens, which are inside the capture, are of equal size
|
||||||
|
@ -420,8 +412,6 @@ namespace Greenshot.Addons.Core
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,15 +178,13 @@ namespace Greenshot.Addons.Extensions
|
||||||
/// <param name="outputSettings">SurfaceOutputSettings specifying how to output the surface</param>
|
/// <param name="outputSettings">SurfaceOutputSettings specifying how to output the surface</param>
|
||||||
public static void SetAsBitmap(this IClipboardAccessToken clipboardAccessToken, ISurface surface, SurfaceOutputSettings outputSettings)
|
public static void SetAsBitmap(this IClipboardAccessToken clipboardAccessToken, ISurface surface, SurfaceOutputSettings outputSettings)
|
||||||
{
|
{
|
||||||
using (var bitmapStream = new MemoryStream())
|
using var bitmapStream = new MemoryStream();
|
||||||
{
|
|
||||||
ImageOutput.SaveToStream(surface, bitmapStream, outputSettings);
|
ImageOutput.SaveToStream(surface, bitmapStream, outputSettings);
|
||||||
bitmapStream.Seek(0, SeekOrigin.Begin);
|
bitmapStream.Seek(0, SeekOrigin.Begin);
|
||||||
// Set the stream
|
// Set the stream
|
||||||
var clipboardFormat = ClipboardFormatExtensions.MapFormatToId(outputSettings.Format.ToString().ToUpperInvariant());
|
var clipboardFormat = ClipboardFormatExtensions.MapFormatToId(outputSettings.Format.ToString().ToUpperInvariant());
|
||||||
clipboardAccessToken.SetAsStream(clipboardFormat, bitmapStream);
|
clipboardAccessToken.SetAsStream(clipboardFormat, bitmapStream);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Place the surface as Format17 bitmap on the clipboard
|
/// Place the surface as Format17 bitmap on the clipboard
|
||||||
|
@ -196,8 +194,7 @@ namespace Greenshot.Addons.Extensions
|
||||||
public static void SetAsFormat17(this IClipboardAccessToken clipboardAccessToken, ISurface surface, ICoreConfiguration coreConfiguration)
|
public static void SetAsFormat17(this IClipboardAccessToken clipboardAccessToken, ISurface surface, ICoreConfiguration coreConfiguration)
|
||||||
{
|
{
|
||||||
// Create the stream for the clipboard
|
// Create the stream for the clipboard
|
||||||
using (var dibV5Stream = new MemoryStream())
|
using var dibV5Stream = new MemoryStream();
|
||||||
{
|
|
||||||
var outputSettings = new SurfaceOutputSettings(coreConfiguration, OutputFormats.bmp, 100, false);
|
var outputSettings = new SurfaceOutputSettings(coreConfiguration, OutputFormats.bmp, 100, false);
|
||||||
bool dispose = ImageOutput.CreateBitmapFromSurface(surface, outputSettings, out var bitmapToSave);
|
bool dispose = ImageOutput.CreateBitmapFromSurface(surface, outputSettings, out var bitmapToSave);
|
||||||
// Create the BITMAPINFOHEADER
|
// Create the BITMAPINFOHEADER
|
||||||
|
@ -230,7 +227,6 @@ namespace Greenshot.Addons.Extensions
|
||||||
bitmapToSave.Dispose();
|
bitmapToSave.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper method so get the bitmap bytes
|
/// Helper method so get the bitmap bytes
|
||||||
|
@ -269,8 +265,7 @@ namespace Greenshot.Addons.Extensions
|
||||||
/// <param name="surface">ISurface</param>
|
/// <param name="surface">ISurface</param>
|
||||||
public static void SetAsDeviceIndependendBitmap(this IClipboardAccessToken clipboardAccessToken, ISurface surface, ICoreConfiguration coreConfiguration)
|
public static void SetAsDeviceIndependendBitmap(this IClipboardAccessToken clipboardAccessToken, ISurface surface, ICoreConfiguration coreConfiguration)
|
||||||
{
|
{
|
||||||
using (var bitmapStream = new MemoryStream())
|
using var bitmapStream = new MemoryStream();
|
||||||
{
|
|
||||||
ImageOutput.SaveToStream(surface, bitmapStream, new SurfaceOutputSettings(coreConfiguration) {Format = OutputFormats.bmp});
|
ImageOutput.SaveToStream(surface, bitmapStream, new SurfaceOutputSettings(coreConfiguration) {Format = OutputFormats.bmp});
|
||||||
bitmapStream.Seek(Marshal.SizeOf(typeof(BitmapFileHeader)), SeekOrigin.Begin);
|
bitmapStream.Seek(Marshal.SizeOf(typeof(BitmapFileHeader)), SeekOrigin.Begin);
|
||||||
// Set the stream
|
// Set the stream
|
||||||
|
@ -278,4 +273,3 @@ namespace Greenshot.Addons.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -155,8 +155,7 @@ EndSelection:<<<<<<<4
|
||||||
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
/// <param name="coreConfiguration">ICoreConfiguration</param>
|
||||||
public static void SetAsEmbeddedHtml(this IClipboardAccessToken clipboardAccessToken, ISurface surface, ICoreConfiguration coreConfiguration)
|
public static void SetAsEmbeddedHtml(this IClipboardAccessToken clipboardAccessToken, ISurface surface, ICoreConfiguration coreConfiguration)
|
||||||
{
|
{
|
||||||
using (var pngStream = new MemoryStream())
|
using var pngStream = new MemoryStream();
|
||||||
{
|
|
||||||
var pngOutputSettings = new SurfaceOutputSettings(coreConfiguration, OutputFormats.png, 100, false);
|
var pngOutputSettings = new SurfaceOutputSettings(coreConfiguration, OutputFormats.png, 100, false);
|
||||||
ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings);
|
ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings);
|
||||||
pngStream.Seek(0, SeekOrigin.Begin);
|
pngStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
@ -164,7 +163,6 @@ EndSelection:<<<<<<<4
|
||||||
var htmlText = GenerateHtmlDataUrlString(new NativeSize(surface.Width, surface.Height), pngStream);
|
var htmlText = GenerateHtmlDataUrlString(new NativeSize(surface.Width, surface.Height), pngStream);
|
||||||
clipboardAccessToken.SetAsHtml(htmlText);
|
clipboardAccessToken.SetAsHtml(htmlText);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Place HTML on the clipboard
|
/// Place HTML on the clipboard
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="2.1.3" />
|
<PackageReference Include="Dapplo.CaliburnMicro.Configuration" Version="2.1.4" />
|
||||||
<PackageReference Include="Dapplo.CaliburnMicro.Metro" Version="2.1.3" />
|
<PackageReference Include="Dapplo.CaliburnMicro.Metro" Version="2.1.4" />
|
||||||
<PackageReference Include="Dapplo.CaliburnMicro.Toasts" Version="2.1.3" />
|
<PackageReference Include="Dapplo.CaliburnMicro.Toasts" Version="2.1.4" />
|
||||||
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="2.1.3" />
|
<PackageReference Include="Dapplo.CaliburnMicro.Translations" Version="2.1.4" />
|
||||||
<PackageReference Include="Dapplo.HttpExtensions" Version="0.10.7" />
|
<PackageReference Include="Dapplo.HttpExtensions" Version="0.10.7" />
|
||||||
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.10.7" />
|
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="0.10.7" />
|
||||||
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.10.7" />
|
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="0.10.7" />
|
||||||
|
@ -27,9 +27,9 @@
|
||||||
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.11.6" />
|
<PackageReference Include="Dapplo.Windows.Clipboard" Version="0.11.6" />
|
||||||
<PackageReference Include="Dapplo.Windows.Dpi" Version="0.11.6" />
|
<PackageReference Include="Dapplo.Windows.Dpi" Version="0.11.6" />
|
||||||
<PackageReference Include="Dapplo.Windows.Icons" Version="0.11.6" />
|
<PackageReference Include="Dapplo.Windows.Icons" Version="0.11.6" />
|
||||||
<PackageReference Include="gong-wpf-dragdrop" Version="2.1.0" />
|
<PackageReference Include="gong-wpf-dragdrop" Version="2.2.0" />
|
||||||
<PackageReference Include="MahApps.Metro.IconPacks" Version="3.0.0-alpha0223" />
|
<PackageReference Include="MahApps.Metro.IconPacks" Version="3.0.0" />
|
||||||
<PackageReference Include="Svg" Version="3.0.49" />
|
<PackageReference Include="Svg" Version="3.0.84" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -48,11 +48,9 @@ namespace Greenshot.Addons.Resources
|
||||||
/// <returns>BitmapSource</returns>
|
/// <returns>BitmapSource</returns>
|
||||||
public BitmapSource GreenshotIconAsBitmapSource()
|
public BitmapSource GreenshotIconAsBitmapSource()
|
||||||
{
|
{
|
||||||
using (var icon = GetGreenshotIcon())
|
using var icon = GetGreenshotIcon();
|
||||||
{
|
|
||||||
return icon.ToBitmapSource();
|
return icon.ToBitmapSource();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the Greenshot logo as an Icon
|
/// Get the Greenshot logo as an Icon
|
||||||
|
@ -71,11 +69,9 @@ namespace Greenshot.Addons.Resources
|
||||||
/// <returns>Icon</returns>
|
/// <returns>Icon</returns>
|
||||||
public Icon GetIcon(string name, Type type = null)
|
public Icon GetIcon(string name, Type type = null)
|
||||||
{
|
{
|
||||||
using (var iconStream = _resourceProvider.ResourceAsStream((type ?? GetType()).Assembly, "Resources", $"{name}.Icon.ico"))
|
using var iconStream = _resourceProvider.ResourceAsStream((type ?? GetType()).Assembly, "Resources", $"{name}.Icon.ico");
|
||||||
{
|
|
||||||
return new Icon(iconStream);
|
return new Icon(iconStream);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the Greenshot logo as a Bitmap
|
/// Get the Greenshot logo as a Bitmap
|
||||||
|
@ -99,11 +95,10 @@ namespace Greenshot.Addons.Resources
|
||||||
name += ".png";
|
name += ".png";
|
||||||
|
|
||||||
}
|
}
|
||||||
using (var imageStream = _resourceProvider.ResourceAsStream((type ?? GetType()).Assembly, "Resources", name))
|
|
||||||
{
|
using var imageStream = _resourceProvider.ResourceAsStream((type ?? GetType()).Assembly, "Resources", name);
|
||||||
return BitmapHelper.FromStream(imageStream);
|
return BitmapHelper.FromStream(imageStream);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a byte[] from an embedded resource
|
/// Get a byte[] from an embedded resource
|
||||||
|
@ -113,12 +108,10 @@ namespace Greenshot.Addons.Resources
|
||||||
/// <returns>bate[]</returns>
|
/// <returns>bate[]</returns>
|
||||||
public byte[] GetBytes(string name, Type type = null)
|
public byte[] GetBytes(string name, Type type = null)
|
||||||
{
|
{
|
||||||
using (var stream = _resourceProvider.ResourceAsStream((type ?? GetType()).Assembly, "Resources", name))
|
using var stream = _resourceProvider.ResourceAsStream((type ?? GetType()).Assembly, "Resources", name);
|
||||||
using (var memoryStream = new MemoryStream())
|
using var memoryStream = new MemoryStream();
|
||||||
{
|
|
||||||
stream.CopyTo(memoryStream);
|
stream.CopyTo(memoryStream);
|
||||||
return memoryStream.ToArray();
|
return memoryStream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -63,11 +63,9 @@ namespace Greenshot.Addons.ViewModels
|
||||||
Information = exportInformation;
|
Information = exportInformation;
|
||||||
Source = source;
|
Source = source;
|
||||||
|
|
||||||
using (var bitmap = exportedSurface.GetBitmapForExport())
|
using var bitmap = exportedSurface.GetBitmapForExport();
|
||||||
{
|
|
||||||
ExportBitmapSource = bitmap.NativeBitmap.ToBitmapSource();
|
ExportBitmapSource = bitmap.NativeBitmap.ToBitmapSource();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The greenshot icon
|
/// The greenshot icon
|
||||||
|
|
|
@ -112,10 +112,11 @@ namespace Greenshot.Addons.ViewModels
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SelectOutputPath()
|
public void SelectOutputPath()
|
||||||
{
|
{
|
||||||
using (var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog())
|
using var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog
|
||||||
{
|
{
|
||||||
|
SelectedPath = FilenameHelper.FillVariables(CoreConfiguration.OutputFilePath, false)
|
||||||
|
};
|
||||||
// Get the storage location and replace the environment variables
|
// Get the storage location and replace the environment variables
|
||||||
folderBrowserDialog.SelectedPath = FilenameHelper.FillVariables(CoreConfiguration.OutputFilePath, false);
|
|
||||||
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||||
{
|
{
|
||||||
// Only change if there is a change, otherwise we might overwrite the environment variables
|
// Only change if there is a change, otherwise we might overwrite the environment variables
|
||||||
|
@ -125,7 +126,6 @@ namespace Greenshot.Addons.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies if the global settings can be modified, which is the case when there are is no DestinationFileConfiguration
|
/// Specifies if the global settings can be modified, which is the case when there are is no DestinationFileConfiguration
|
||||||
|
|
|
@ -166,8 +166,7 @@ namespace Greenshot.Core.Extensions
|
||||||
{
|
{
|
||||||
// Assume using it's own location
|
// Assume using it's own location
|
||||||
formLocation = windowRectangle.Location;
|
formLocation = windowRectangle.Location;
|
||||||
using (var workingArea = new Region())
|
using var workingArea = new Region();
|
||||||
{
|
|
||||||
// Find the screen where the window is and check if it fits
|
// Find the screen where the window is and check if it fits
|
||||||
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
|
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
|
||||||
{
|
{
|
||||||
|
@ -196,7 +195,6 @@ namespace Greenshot.Core.Extensions
|
||||||
doesCaptureFit = true;
|
doesCaptureFit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (!WindowsVersion.IsWindows8OrLater)
|
else if (!WindowsVersion.IsWindows8OrLater)
|
||||||
{
|
{
|
||||||
//GetClientRect(out windowRectangle);
|
//GetClientRect(out windowRectangle);
|
||||||
|
@ -229,8 +227,7 @@ namespace Greenshot.Core.Extensions
|
||||||
if (!doesCaptureFit)
|
if (!doesCaptureFit)
|
||||||
{
|
{
|
||||||
// if GDI is allowed.. (a screenshot won't be better than we comes if we continue)
|
// if GDI is allowed.. (a screenshot won't be better than we comes if we continue)
|
||||||
using (var thisWindowProcess = Process.GetProcessById(interopWindow.GetProcessId()))
|
using var thisWindowProcess = Process.GetProcessById(interopWindow.GetProcessId());
|
||||||
{
|
|
||||||
if (!interopWindow.IsApp() && IsGdiAllowed(thisWindowProcess, captureConfiguration))
|
if (!interopWindow.IsApp() && IsGdiAllowed(thisWindowProcess, captureConfiguration))
|
||||||
{
|
{
|
||||||
// we return null which causes the capturing code to try another method.
|
// we return null which causes the capturing code to try another method.
|
||||||
|
@ -239,7 +236,6 @@ namespace Greenshot.Core.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Prepare the displaying of the Thumbnail
|
// Prepare the displaying of the Thumbnail
|
||||||
var props = new DwmThumbnailProperties
|
var props = new DwmThumbnailProperties
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,8 +95,7 @@ namespace Greenshot.Core.Sources
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a device context we can copy to
|
// create a device context we can copy to
|
||||||
using (var safeCompatibleDcHandle = Gdi32Api.CreateCompatibleDC(desktopDcHandle))
|
using var safeCompatibleDcHandle = Gdi32Api.CreateCompatibleDC(desktopDcHandle);
|
||||||
{
|
|
||||||
// Check if the device context is there, if not throw an error with as much info as possible!
|
// Check if the device context is there, if not throw an error with as much info as possible!
|
||||||
if (safeCompatibleDcHandle.IsInvalid)
|
if (safeCompatibleDcHandle.IsInvalid)
|
||||||
{
|
{
|
||||||
|
@ -112,8 +111,7 @@ namespace Greenshot.Core.Sources
|
||||||
Win32.SetLastError(0);
|
Win32.SetLastError(0);
|
||||||
|
|
||||||
// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
|
// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
|
||||||
using (var safeDibSectionHandle = Gdi32Api.CreateDIBSection(desktopDcHandle, ref bmi, 0, out var _, IntPtr.Zero, 0))
|
using var safeDibSectionHandle = Gdi32Api.CreateDIBSection(desktopDcHandle, ref bmi, 0, out var _, IntPtr.Zero, 0);
|
||||||
{
|
|
||||||
if (safeDibSectionHandle.IsInvalid)
|
if (safeDibSectionHandle.IsInvalid)
|
||||||
{
|
{
|
||||||
// Get Exception before the error is lost
|
// Get Exception before the error is lost
|
||||||
|
@ -157,11 +155,9 @@ namespace Greenshot.Core.Sources
|
||||||
captureRegion.Exclude(displayInfo.Bounds);
|
captureRegion.Exclude(displayInfo.Bounds);
|
||||||
}
|
}
|
||||||
// If the region is not empty, we have "offscreenContent"
|
// If the region is not empty, we have "offscreenContent"
|
||||||
using (var screenGraphics = Graphics.FromHwnd(User32Api.GetDesktopWindow()))
|
using var screenGraphics = Graphics.FromHwnd(User32Api.GetDesktopWindow());
|
||||||
{
|
|
||||||
offscreenContent = !captureRegion.IsEmpty(screenGraphics);
|
offscreenContent = !captureRegion.IsEmpty(screenGraphics);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Check if we need to have a transparent background, needed for offscreen content
|
// Check if we need to have a transparent background, needed for offscreen content
|
||||||
if (offscreenContent)
|
if (offscreenContent)
|
||||||
{
|
{
|
||||||
|
@ -174,8 +170,6 @@ namespace Greenshot.Core.Sources
|
||||||
capturedBitmapSource = modifiedImage;
|
capturedBitmapSource = modifiedImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
var result = new CaptureElement<BitmapSource>(captureBounds.Location, capturedBitmapSource)
|
var result = new CaptureElement<BitmapSource>(captureBounds.Location, capturedBitmapSource)
|
||||||
{
|
{
|
||||||
ElementType = CaptureElementType.Screen
|
ElementType = CaptureElementType.Screen
|
||||||
|
|
|
@ -171,8 +171,7 @@ namespace Greenshot.Gfx
|
||||||
// Make sure both images have the same resolution
|
// Make sure both images have the same resolution
|
||||||
newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
newImage.SetResolution(sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
||||||
|
|
||||||
using (var graphics = Graphics.FromImage(newImage))
|
using var graphics = Graphics.FromImage(newImage);
|
||||||
{
|
|
||||||
if (fromTransparentToNon)
|
if (fromTransparentToNon)
|
||||||
{
|
{
|
||||||
// Rule 2: Make sure the background color is white
|
// Rule 2: Make sure the background color is white
|
||||||
|
@ -188,7 +187,6 @@ namespace Greenshot.Gfx
|
||||||
graphics.DrawImage(sourceBitmap.NativeBitmap, 0, 0, sourceRect, GraphicsUnit.Pixel);
|
graphics.DrawImage(sourceBitmap.NativeBitmap, 0, 0, sourceRect, GraphicsUnit.Pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Let GDI+ decide how to convert, need to test what is quicker...
|
// Let GDI+ decide how to convert, need to test what is quicker...
|
||||||
|
|
|
@ -462,13 +462,11 @@ namespace Greenshot.Gfx
|
||||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
// draw original with a TextureBrush so we have nice anti-aliasing!
|
// draw original with a TextureBrush so we have nice anti-aliasing!
|
||||||
using (Brush textureBrush = new TextureBrush(sourceBitmap.NativeBitmap, WrapMode.Clamp))
|
using Brush textureBrush = new TextureBrush(sourceBitmap.NativeBitmap, WrapMode.Clamp);
|
||||||
{
|
|
||||||
// We need to do a translate-transform otherwise the image is wrapped
|
// We need to do a translate-transform otherwise the image is wrapped
|
||||||
graphics.TranslateTransform(offset.X, offset.Y);
|
graphics.TranslateTransform(offset.X, offset.Y);
|
||||||
graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return returnImage;
|
return returnImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,13 +490,11 @@ namespace Greenshot.Gfx
|
||||||
/// <param name="colorMatrix">ColorMatrix to apply</param>
|
/// <param name="colorMatrix">ColorMatrix to apply</param>
|
||||||
public static void ApplyColorMatrix(this IBitmapWithNativeSupport source, NativeRect sourceRect, IBitmapWithNativeSupport dest, NativeRect destRect, ColorMatrix colorMatrix)
|
public static void ApplyColorMatrix(this IBitmapWithNativeSupport source, NativeRect sourceRect, IBitmapWithNativeSupport dest, NativeRect destRect, ColorMatrix colorMatrix)
|
||||||
{
|
{
|
||||||
using (var imageAttributes = new ImageAttributes())
|
using var imageAttributes = new ImageAttributes();
|
||||||
{
|
|
||||||
imageAttributes.ClearColorMatrix();
|
imageAttributes.ClearColorMatrix();
|
||||||
imageAttributes.SetColorMatrix(colorMatrix);
|
imageAttributes.SetColorMatrix(colorMatrix);
|
||||||
source.ApplyImageAttributes(sourceRect, dest, destRect, imageAttributes);
|
source.ApplyImageAttributes(sourceRect, dest, destRect, imageAttributes);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply image attributes to the image
|
/// Apply image attributes to the image
|
||||||
|
@ -532,8 +528,8 @@ namespace Greenshot.Gfx
|
||||||
{
|
{
|
||||||
destRect = new NativeRect(0, 0, dest.Width, dest.Height);
|
destRect = new NativeRect(0, 0, dest.Width, dest.Height);
|
||||||
}
|
}
|
||||||
using (var graphics = Graphics.FromImage(dest.NativeBitmap))
|
|
||||||
{
|
using var graphics = Graphics.FromImage(dest.NativeBitmap);
|
||||||
// Make sure we draw with the best quality!
|
// Make sure we draw with the best quality!
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
|
@ -543,7 +539,6 @@ namespace Greenshot.Gfx
|
||||||
|
|
||||||
graphics.DrawImage(source.NativeBitmap, destRect, sourceRect.X, sourceRect.Y, sourceRect.Width, sourceRect.Height, GraphicsUnit.Pixel, imageAttributes);
|
graphics.DrawImage(source.NativeBitmap, destRect, sourceRect.X, sourceRect.Y, sourceRect.Width, sourceRect.Height, GraphicsUnit.Pixel, imageAttributes);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the supplied Bitmap has a PixelFormat we support
|
/// Checks if the supplied Bitmap has a PixelFormat we support
|
||||||
|
@ -712,12 +707,10 @@ namespace Greenshot.Gfx
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
graphics.InterpolationMode = interpolationMode;
|
graphics.InterpolationMode = interpolationMode;
|
||||||
using (var wrapMode = new ImageAttributes())
|
using var wrapMode = new ImageAttributes();
|
||||||
{
|
|
||||||
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||||
graphics.DrawImage(sourceImage.NativeBitmap, new NativeRect(destX, destY, destWidth, destHeight), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, wrapMode);
|
graphics.DrawImage(sourceImage.NativeBitmap, new NativeRect(destX, destY, destWidth, destHeight), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, wrapMode);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return newBitmap;
|
return newBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -737,8 +730,8 @@ namespace Greenshot.Gfx
|
||||||
{
|
{
|
||||||
toCount = toCount & 0xffffff;
|
toCount = toCount & 0xffffff;
|
||||||
}
|
}
|
||||||
using (var bb = FastBitmapFactory.Create(sourceImage))
|
|
||||||
{
|
using var bb = FastBitmapFactory.Create(sourceImage);
|
||||||
Parallel.For(0, bb.Height, () => 0, (y, state, initialColorCount) =>
|
Parallel.For(0, bb.Height, () => 0, (y, state, initialColorCount) =>
|
||||||
{
|
{
|
||||||
var currentColors = initialColorCount;
|
var currentColors = initialColorCount;
|
||||||
|
@ -765,7 +758,6 @@ namespace Greenshot.Gfx
|
||||||
|
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create an image from a stream, if an extension is supplied more formats are supported.
|
/// Create an image from a stream, if an extension is supplied more formats are supported.
|
||||||
|
@ -834,11 +826,9 @@ namespace Greenshot.Gfx
|
||||||
}
|
}
|
||||||
if (width == original.Width * 4)
|
if (width == original.Width * 4)
|
||||||
{
|
{
|
||||||
using (var scale2X = original.Scale2X())
|
using var scale2X = original.Scale2X();
|
||||||
{
|
|
||||||
return scale2X.Scale2X();
|
return scale2X.Scale2X();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return original.Resize(true, width, width, interpolationMode: InterpolationMode.NearestNeighbor);
|
return original.Resize(true, width, width, interpolationMode: InterpolationMode.NearestNeighbor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,8 +855,8 @@ namespace Greenshot.Gfx
|
||||||
}
|
}
|
||||||
bool result = true;
|
bool result = true;
|
||||||
using (var fastBitmap1 = FastBitmapFactory.Create(bitmap1))
|
using (var fastBitmap1 = FastBitmapFactory.Create(bitmap1))
|
||||||
using (var fastBitmap2 = FastBitmapFactory.Create(bitmap2))
|
|
||||||
{
|
{
|
||||||
|
using var fastBitmap2 = FastBitmapFactory.Create(bitmap2);
|
||||||
Parallel.For(0, fastBitmap1.Height, (y, state) =>
|
Parallel.For(0, fastBitmap1.Height, (y, state) =>
|
||||||
{
|
{
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -888,6 +878,7 @@ namespace Greenshot.Gfx
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,9 @@ namespace Greenshot.Gfx
|
||||||
public static void ApplyBoxBlur(this IBitmapWithNativeSupport destinationBitmap, int range)
|
public static void ApplyBoxBlur(this IBitmapWithNativeSupport destinationBitmap, int range)
|
||||||
{
|
{
|
||||||
// We only need one fastbitmap as we use it as source and target (the reading is done for one line H/V, writing after "parsing" one line H/V)
|
// We only need one fastbitmap as we use it as source and target (the reading is done for one line H/V, writing after "parsing" one line H/V)
|
||||||
using (var fastBitmap = FastBitmapFactory.Create(destinationBitmap))
|
using var fastBitmap = FastBitmapFactory.Create(destinationBitmap);
|
||||||
{
|
|
||||||
fastBitmap.ApplyBoxBlur(range);
|
fastBitmap.ApplyBoxBlur(range);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply BoxBlur to the fastBitmap
|
/// Apply BoxBlur to the fastBitmap
|
||||||
|
|
|
@ -76,22 +76,19 @@ namespace Greenshot.Gfx.Effects
|
||||||
using (var path = new GraphicsPath())
|
using (var path = new GraphicsPath())
|
||||||
{
|
{
|
||||||
path.AddRectangle(new NativeRect(borderSize >> 1, borderSize >> 1, newImage.Width - borderSize, newImage.Height - borderSize));
|
path.AddRectangle(new NativeRect(borderSize >> 1, borderSize >> 1, newImage.Width - borderSize, newImage.Height - borderSize));
|
||||||
using (var pen = new Pen(borderColor, borderSize))
|
using var pen = new Pen(borderColor, borderSize) {
|
||||||
{
|
LineJoin = LineJoin.Round,
|
||||||
pen.LineJoin = LineJoin.Round;
|
StartCap = LineCap.Round,
|
||||||
pen.StartCap = LineCap.Round;
|
EndCap = LineCap.Round
|
||||||
pen.EndCap = LineCap.Round;
|
};
|
||||||
graphics.DrawPath(pen, path);
|
graphics.DrawPath(pen, path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// draw original with a TextureBrush so we have nice anti-aliasing!
|
// draw original with a TextureBrush so we have nice anti-aliasing!
|
||||||
using (Brush textureBrush = new TextureBrush(sourceBitmap.NativeBitmap, WrapMode.Clamp))
|
using Brush textureBrush = new TextureBrush(sourceBitmap.NativeBitmap, WrapMode.Clamp);
|
||||||
{
|
|
||||||
// We need to do a translate-tranform otherwise the image is wrapped
|
// We need to do a translate-tranform otherwise the image is wrapped
|
||||||
graphics.TranslateTransform(offset.X, offset.Y);
|
graphics.TranslateTransform(offset.X, offset.Y);
|
||||||
graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,7 @@ namespace Greenshot.Gfx.Effects
|
||||||
/// <returns>b/w bitmap</returns>
|
/// <returns>b/w bitmap</returns>
|
||||||
public static IBitmapWithNativeSupport CreateMonochrome(IBitmapWithNativeSupport sourceBitmap, byte threshold)
|
public static IBitmapWithNativeSupport CreateMonochrome(IBitmapWithNativeSupport sourceBitmap, byte threshold)
|
||||||
{
|
{
|
||||||
using (var fastBitmap = FastBitmapFactory.CreateCloneOf(sourceBitmap, sourceBitmap.PixelFormat))
|
using var fastBitmap = FastBitmapFactory.CreateCloneOf(sourceBitmap, sourceBitmap.PixelFormat);
|
||||||
{
|
|
||||||
Parallel.For(0, fastBitmap.Height, y =>
|
Parallel.For(0, fastBitmap.Height, y =>
|
||||||
{
|
{
|
||||||
// TODO: use stackalloc / unsafe
|
// TODO: use stackalloc / unsafe
|
||||||
|
@ -66,7 +65,6 @@ namespace Greenshot.Gfx.Effects
|
||||||
});
|
});
|
||||||
return fastBitmap.UnlockAndReturnBitmap();
|
return fastBitmap.UnlockAndReturnBitmap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,19 +193,15 @@ namespace Greenshot.Gfx.Effects
|
||||||
path.CloseFigure();
|
path.CloseFigure();
|
||||||
|
|
||||||
// Draw the created figure with the original image by using a TextureBrush so we have anti-aliasing
|
// Draw the created figure with the original image by using a TextureBrush so we have anti-aliasing
|
||||||
using (var graphics = Graphics.FromImage(returnBitmap.NativeBitmap))
|
using var graphics = Graphics.FromImage(returnBitmap.NativeBitmap);
|
||||||
{
|
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
using (Brush brush = new TextureBrush(sourceBitmap.NativeBitmap))
|
using Brush brush = new TextureBrush(sourceBitmap.NativeBitmap);
|
||||||
{
|
|
||||||
// Important note: If the target wouldn't be at 0,0 we need to translate-transform!!
|
// Important note: If the target wouldn't be at 0,0 we need to translate-transform!!
|
||||||
graphics.FillPath(brush, path);
|
graphics.FillPath(brush, path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return returnBitmap;
|
return returnBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,35 +34,25 @@ namespace Greenshot.Gfx.Extensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bitmap">IBitmapWithNativeSupport</param>
|
/// <param name="bitmap">IBitmapWithNativeSupport</param>
|
||||||
/// <returns>IBitmapWithNativeSupport</returns>
|
/// <returns>IBitmapWithNativeSupport</returns>
|
||||||
public static IBitmapWithNativeSupport Scale2X(this IBitmapWithNativeSupport bitmap)
|
public static IBitmapWithNativeSupport Scale2X(this IBitmapWithNativeSupport bitmap) =>
|
||||||
|
bitmap switch
|
||||||
{
|
{
|
||||||
switch (bitmap)
|
UnmanagedBitmap<Bgra32> unmanagedBitmap => unmanagedBitmap.Scale2X(),
|
||||||
{
|
UnmanagedBitmap<Bgr32> unmanagedBitmap => unmanagedBitmap.Scale2X(),
|
||||||
case UnmanagedBitmap<Bgra32> unmanagedBitmap:
|
_ => ScaleX.Scale2X(bitmap)
|
||||||
return unmanagedBitmap.Scale2X();
|
};
|
||||||
case UnmanagedBitmap<Bgr32> unmanagedBitmap:
|
|
||||||
return unmanagedBitmap.Scale2X();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ScaleX.Scale2X(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scale3x
|
/// Scale3x
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bitmap">IBitmapWithNativeSupport</param>
|
/// <param name="bitmap">IBitmapWithNativeSupport</param>
|
||||||
/// <returns>IBitmapWithNativeSupport</returns>
|
/// <returns>IBitmapWithNativeSupport</returns>
|
||||||
public static IBitmapWithNativeSupport Scale3X(this IBitmapWithNativeSupport bitmap)
|
public static IBitmapWithNativeSupport Scale3X(this IBitmapWithNativeSupport bitmap) =>
|
||||||
|
bitmap switch
|
||||||
{
|
{
|
||||||
switch (bitmap)
|
UnmanagedBitmap<Bgra32> unmanagedBitmap => unmanagedBitmap.Scale3X(),
|
||||||
{
|
UnmanagedBitmap<Bgr32> unmanagedBitmap => unmanagedBitmap.Scale3X(),
|
||||||
case UnmanagedBitmap<Bgra32> unmanagedBitmap:
|
_ => ScaleX.Scale3X(bitmap)
|
||||||
return unmanagedBitmap.Scale3X();
|
};
|
||||||
case UnmanagedBitmap<Bgr32> unmanagedBitmap:
|
|
||||||
return unmanagedBitmap.Scale3X();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ScaleX.Scale3X(bitmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -20,8 +19,7 @@ namespace Greenshot.Gfx.Formats
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IBitmapWithNativeSupport Read(Stream stream, string extension = null)
|
public IBitmapWithNativeSupport Read(Stream stream, string extension = null)
|
||||||
{
|
{
|
||||||
using (var tmpImage = Image.FromStream(stream, true, true))
|
using var tmpImage = Image.FromStream(stream, true, true);
|
||||||
{
|
|
||||||
if (!(tmpImage is Bitmap bitmap))
|
if (!(tmpImage is Bitmap bitmap))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -31,4 +29,3 @@ namespace Greenshot.Gfx.Formats
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -28,14 +28,12 @@ namespace Greenshot.Gfx.Formats
|
||||||
// Icon logic, try to get the Vista icon, else the biggest possible
|
// Icon logic, try to get the Vista icon, else the biggest possible
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var tmpBitmap = ExtractVistaIcon(stream))
|
using var tmpBitmap = ExtractVistaIcon(stream);
|
||||||
{
|
|
||||||
if (tmpBitmap != null)
|
if (tmpBitmap != null)
|
||||||
{
|
{
|
||||||
return tmpBitmap.CloneBitmap(PixelFormat.Format32bppArgb);
|
return tmpBitmap.CloneBitmap(PixelFormat.Format32bppArgb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception vistaIconException)
|
catch (Exception vistaIconException)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(vistaIconException, "Can't read icon");
|
Log.Warn().WriteLine(vistaIconException, "Can't read icon");
|
||||||
|
@ -45,14 +43,10 @@ namespace Greenshot.Gfx.Formats
|
||||||
// No vista icon, try normal icon
|
// No vista icon, try normal icon
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
// We create a copy of the bitmap, so everything else can be disposed
|
// We create a copy of the bitmap, so everything else can be disposed
|
||||||
using (var tmpIcon = new Icon(stream, new Size(1024, 1024)))
|
using var tmpIcon = new Icon(stream, new Size(1024, 1024));
|
||||||
{
|
using var tmpImage = tmpIcon.ToBitmap();
|
||||||
using (var tmpImage = tmpIcon.ToBitmap())
|
|
||||||
{
|
|
||||||
return tmpImage.CloneBitmap(PixelFormat.Format32bppArgb);
|
return tmpImage.CloneBitmap(PixelFormat.Format32bppArgb);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception iconException)
|
catch (Exception iconException)
|
||||||
{
|
{
|
||||||
Log.Warn().WriteLine(iconException, "Can't read icon");
|
Log.Warn().WriteLine(iconException, "Can't read icon");
|
||||||
|
@ -89,12 +83,10 @@ namespace Greenshot.Gfx.Formats
|
||||||
}
|
}
|
||||||
var iImageSize = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 8);
|
var iImageSize = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 8);
|
||||||
var iImageOffset = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 12);
|
var iImageOffset = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 12);
|
||||||
using (var destStream = new MemoryStream())
|
using var destStream = new MemoryStream();
|
||||||
{
|
|
||||||
destStream.Write(srcBuf, iImageOffset, iImageSize);
|
destStream.Write(srcBuf, iImageOffset, iImageSize);
|
||||||
destStream.Seek(0, SeekOrigin.Begin);
|
destStream.Seek(0, SeekOrigin.Begin);
|
||||||
bmpPngExtracted = BitmapWrapper.FromBitmap(new Bitmap(destStream)); // This is PNG! :)
|
bmpPngExtracted = BitmapWrapper.FromBitmap(new Bitmap(destStream)); // This is PNG! :)
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<PackageReference Include="Dapplo.Log" Version="1.3.26" />
|
<PackageReference Include="Dapplo.Log" Version="1.3.26" />
|
||||||
<PackageReference Include="Dapplo.Windows" Version="0.11.6" />
|
<PackageReference Include="Dapplo.Windows" Version="0.11.6" />
|
||||||
<PackageReference Include="Dapplo.Windows.Dpi" Version="0.11.6" />
|
<PackageReference Include="Dapplo.Windows.Dpi" Version="0.11.6" />
|
||||||
<PackageReference Include="Svg" Version="3.0.49" />
|
<PackageReference Include="Svg" Version="3.0.84" />
|
||||||
<PackageReference Include="System.Memory" Version="4.5.3" />
|
<PackageReference Include="System.Memory" Version="4.5.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -105,11 +105,9 @@ namespace Greenshot.Gfx.Quantizer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a bitmap to store the initial match, which is just as good as an array and saves us 2x the storage
|
// Use a bitmap to store the initial match, which is just as good as an array and saves us 2x the storage
|
||||||
using (var sourceFastBitmap = FastBitmapFactory.Create(sourceBitmap))
|
using var sourceFastBitmap = FastBitmapFactory.Create(sourceBitmap);
|
||||||
{
|
|
||||||
sourceFastBitmap.Lock();
|
sourceFastBitmap.Lock();
|
||||||
using (var destinationFastBitmap = FastBitmapFactory.CreateEmpty(sourceBitmap.Size, PixelFormat.Format8bppIndexed, Color.White) as FastChunkyBitmap)
|
using var destinationFastBitmap = FastBitmapFactory.CreateEmpty(sourceBitmap.Size, PixelFormat.Format8bppIndexed, Color.White) as FastChunkyBitmap;
|
||||||
{
|
|
||||||
for (var y = 0; y < sourceFastBitmap.Height; y++)
|
for (var y = 0; y < sourceFastBitmap.Height; y++)
|
||||||
{
|
{
|
||||||
for (var x = 0; x < sourceFastBitmap.Width; x++)
|
for (var x = 0; x < sourceFastBitmap.Width; x++)
|
||||||
|
@ -150,8 +148,6 @@ namespace Greenshot.Gfx.Quantizer
|
||||||
}
|
}
|
||||||
_resultBitmap = destinationFastBitmap.UnlockAndReturnBitmap();
|
_resultBitmap = destinationFastBitmap.UnlockAndReturnBitmap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -200,8 +196,7 @@ namespace Greenshot.Gfx.Quantizer
|
||||||
using (var bbbDest = FastBitmapFactory.Create(_resultBitmap) as FastChunkyBitmap)
|
using (var bbbDest = FastBitmapFactory.Create(_resultBitmap) as FastChunkyBitmap)
|
||||||
{
|
{
|
||||||
bbbDest.Lock();
|
bbbDest.Lock();
|
||||||
using (var bbbSrc = FastBitmapFactory.Create(_sourceBitmap))
|
using var bbbSrc = FastBitmapFactory.Create(_sourceBitmap);
|
||||||
{
|
|
||||||
bbbSrc.Lock();
|
bbbSrc.Lock();
|
||||||
for (var y = 0; y < bbbSrc.Height; y++)
|
for (var y = 0; y < bbbSrc.Height; y++)
|
||||||
{
|
{
|
||||||
|
@ -231,7 +226,6 @@ namespace Greenshot.Gfx.Quantizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// generates palette
|
// generates palette
|
||||||
var imagePalette = _resultBitmap.NativeBitmap.Palette;
|
var imagePalette = _resultBitmap.NativeBitmap.Palette;
|
||||||
|
@ -349,8 +343,7 @@ namespace Greenshot.Gfx.Quantizer
|
||||||
|
|
||||||
using (var dest = FastBitmapFactory.Create(_resultBitmap) as FastChunkyBitmap)
|
using (var dest = FastBitmapFactory.Create(_resultBitmap) as FastChunkyBitmap)
|
||||||
{
|
{
|
||||||
using (var src = FastBitmapFactory.Create(_sourceBitmap))
|
using var src = FastBitmapFactory.Create(_sourceBitmap);
|
||||||
{
|
|
||||||
var lookup = new Dictionary<Color, byte>();
|
var lookup = new Dictionary<Color, byte>();
|
||||||
for (var y = 0; y < src.Height; y++)
|
for (var y = 0; y < src.Height; y++)
|
||||||
{
|
{
|
||||||
|
@ -412,7 +405,6 @@ namespace Greenshot.Gfx.Quantizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// generates palette
|
// generates palette
|
||||||
|
@ -524,61 +516,44 @@ namespace Greenshot.Gfx.Quantizer
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Splits the cube in given position, and color direction.
|
/// Splits the cube in given position, and color direction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static long Top(WuColorCube cube, int direction, int position, long[,,] moment)
|
private static long Top(WuColorCube cube, int direction, int position, long[,,] moment) =>
|
||||||
|
direction switch
|
||||||
{
|
{
|
||||||
switch (direction)
|
Red => (moment[position, cube.GreenMaximum, cube.BlueMaximum] -
|
||||||
{
|
|
||||||
case Red:
|
|
||||||
return moment[position, cube.GreenMaximum, cube.BlueMaximum] -
|
|
||||||
moment[position, cube.GreenMaximum, cube.BlueMinimum] -
|
moment[position, cube.GreenMaximum, cube.BlueMinimum] -
|
||||||
moment[position, cube.GreenMinimum, cube.BlueMaximum] +
|
moment[position, cube.GreenMinimum, cube.BlueMaximum] +
|
||||||
moment[position, cube.GreenMinimum, cube.BlueMinimum];
|
moment[position, cube.GreenMinimum, cube.BlueMinimum]),
|
||||||
|
Green => (moment[cube.RedMaximum, position, cube.BlueMaximum] -
|
||||||
case Green:
|
|
||||||
return moment[cube.RedMaximum, position, cube.BlueMaximum] -
|
|
||||||
moment[cube.RedMaximum, position, cube.BlueMinimum] -
|
moment[cube.RedMaximum, position, cube.BlueMinimum] -
|
||||||
moment[cube.RedMinimum, position, cube.BlueMaximum] +
|
moment[cube.RedMinimum, position, cube.BlueMaximum] +
|
||||||
moment[cube.RedMinimum, position, cube.BlueMinimum];
|
moment[cube.RedMinimum, position, cube.BlueMinimum]),
|
||||||
|
Blue => (moment[cube.RedMaximum, cube.GreenMaximum, position] -
|
||||||
case Blue:
|
|
||||||
return moment[cube.RedMaximum, cube.GreenMaximum, position] -
|
|
||||||
moment[cube.RedMaximum, cube.GreenMinimum, position] -
|
moment[cube.RedMaximum, cube.GreenMinimum, position] -
|
||||||
moment[cube.RedMinimum, cube.GreenMaximum, position] +
|
moment[cube.RedMinimum, cube.GreenMaximum, position] +
|
||||||
moment[cube.RedMinimum, cube.GreenMinimum, position];
|
moment[cube.RedMinimum, cube.GreenMinimum, position]),
|
||||||
|
_ => 0
|
||||||
default:
|
};
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Splits the cube in a given color direction at its minimum.
|
/// Splits the cube in a given color direction at its minimum.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static long Bottom(WuColorCube cube, int direction, long[,,] moment)
|
private static long Bottom(WuColorCube cube, int direction, long[,,] moment) =>
|
||||||
|
direction switch
|
||||||
{
|
{
|
||||||
switch (direction)
|
Red => (-moment[cube.RedMinimum, cube.GreenMaximum, cube.BlueMaximum] +
|
||||||
{
|
|
||||||
case Red:
|
|
||||||
return -moment[cube.RedMinimum, cube.GreenMaximum, cube.BlueMaximum] +
|
|
||||||
moment[cube.RedMinimum, cube.GreenMaximum, cube.BlueMinimum] +
|
moment[cube.RedMinimum, cube.GreenMaximum, cube.BlueMinimum] +
|
||||||
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMaximum] -
|
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMaximum] -
|
||||||
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMinimum];
|
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMinimum]),
|
||||||
|
Green => (-moment[cube.RedMaximum, cube.GreenMinimum, cube.BlueMaximum] +
|
||||||
case Green:
|
|
||||||
return -moment[cube.RedMaximum, cube.GreenMinimum, cube.BlueMaximum] +
|
|
||||||
moment[cube.RedMaximum, cube.GreenMinimum, cube.BlueMinimum] +
|
moment[cube.RedMaximum, cube.GreenMinimum, cube.BlueMinimum] +
|
||||||
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMaximum] -
|
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMaximum] -
|
||||||
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMinimum];
|
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMinimum]),
|
||||||
|
Blue => (-moment[cube.RedMaximum, cube.GreenMaximum, cube.BlueMinimum] +
|
||||||
case Blue:
|
|
||||||
return -moment[cube.RedMaximum, cube.GreenMaximum, cube.BlueMinimum] +
|
|
||||||
moment[cube.RedMaximum, cube.GreenMinimum, cube.BlueMinimum] +
|
moment[cube.RedMaximum, cube.GreenMinimum, cube.BlueMinimum] +
|
||||||
moment[cube.RedMinimum, cube.GreenMaximum, cube.BlueMinimum] -
|
moment[cube.RedMinimum, cube.GreenMaximum, cube.BlueMinimum] -
|
||||||
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMinimum];
|
moment[cube.RedMinimum, cube.GreenMinimum, cube.BlueMinimum]),
|
||||||
default:
|
_ => 0
|
||||||
return 0;
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates statistical variance for a given cube.
|
/// Calculates statistical variance for a given cube.
|
||||||
|
|
|
@ -36,9 +36,8 @@ namespace Greenshot.Gfx
|
||||||
/// <param name="original">Bitmap to scale 2x</param>
|
/// <param name="original">Bitmap to scale 2x</param>
|
||||||
public static IBitmapWithNativeSupport Scale2X(IBitmapWithNativeSupport original)
|
public static IBitmapWithNativeSupport Scale2X(IBitmapWithNativeSupport original)
|
||||||
{
|
{
|
||||||
using (var source = (IFastBitmapWithClip)FastBitmapFactory.Create(original))
|
using var source = (IFastBitmapWithClip)FastBitmapFactory.Create(original);
|
||||||
using (var destination = (IFastBitmapWithClip)FastBitmapFactory.CreateEmpty(new Size(original.Width << 1, original.Height << 1), original.PixelFormat))
|
using var destination = (IFastBitmapWithClip)FastBitmapFactory.CreateEmpty(new Size(original.Width << 1, original.Height << 1), original.PixelFormat);
|
||||||
{
|
|
||||||
// Every pixel from input texture produces 4 output pixels, for more details check out http://scale2x.sourceforge.net/algorithm.html
|
// Every pixel from input texture produces 4 output pixels, for more details check out http://scale2x.sourceforge.net/algorithm.html
|
||||||
Parallel.For(0, source.Height, y =>
|
Parallel.For(0, source.Height, y =>
|
||||||
{
|
{
|
||||||
|
@ -86,7 +85,6 @@ namespace Greenshot.Gfx
|
||||||
});
|
});
|
||||||
return destination.UnlockAndReturnBitmap();
|
return destination.UnlockAndReturnBitmap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use "Scale3x" algorithm to produce bitmap from the original.
|
/// Use "Scale3x" algorithm to produce bitmap from the original.
|
||||||
|
@ -95,9 +93,8 @@ namespace Greenshot.Gfx
|
||||||
[SuppressMessage("ReSharper", "AccessToDisposedClosure")]
|
[SuppressMessage("ReSharper", "AccessToDisposedClosure")]
|
||||||
public static IBitmapWithNativeSupport Scale3X(IBitmapWithNativeSupport original)
|
public static IBitmapWithNativeSupport Scale3X(IBitmapWithNativeSupport original)
|
||||||
{
|
{
|
||||||
using (var source = (IFastBitmapWithClip)FastBitmapFactory.Create(original))
|
using var source = (IFastBitmapWithClip)FastBitmapFactory.Create(original);
|
||||||
using (var destination = (IFastBitmapWithClip)FastBitmapFactory.CreateEmpty(new Size(original.Width * 3, original.Height * 3), original.PixelFormat))
|
using var destination = (IFastBitmapWithClip)FastBitmapFactory.CreateEmpty(new Size(original.Width * 3, original.Height * 3), original.PixelFormat);
|
||||||
{
|
|
||||||
// Every pixel from input texture produces 6 output pixels, for more details check out http://scale2x.sourceforge.net/algorithm.html
|
// Every pixel from input texture produces 6 output pixels, for more details check out http://scale2x.sourceforge.net/algorithm.html
|
||||||
Parallel.For(0, source.Height, y =>
|
Parallel.For(0, source.Height, y =>
|
||||||
{
|
{
|
||||||
|
@ -178,7 +175,6 @@ namespace Greenshot.Gfx
|
||||||
});
|
});
|
||||||
return destination.UnlockAndReturnBitmap();
|
return destination.UnlockAndReturnBitmap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the colors are the same.
|
/// Checks if the colors are the same.
|
||||||
|
|
|
@ -133,24 +133,14 @@ namespace Greenshot.Gfx
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
PixelFormat format;
|
|
||||||
TPixelLayout empty = default;
|
TPixelLayout empty = default;
|
||||||
switch (empty)
|
return empty switch
|
||||||
{
|
{
|
||||||
case Bgr24 _:
|
Bgr24 _ => PixelFormat.Format24bppRgb,
|
||||||
format = PixelFormat.Format24bppRgb;
|
Bgra32 _ => PixelFormat.Format32bppArgb,
|
||||||
break;
|
Bgr32 _ => PixelFormat.Format32bppRgb,
|
||||||
case Bgra32 _:
|
_ => throw new NotSupportedException("Unknown pixel format")
|
||||||
format = PixelFormat.Format32bppArgb;
|
};
|
||||||
break;
|
|
||||||
case Bgr32 _:
|
|
||||||
format = PixelFormat.Format32bppRgb;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new NotSupportedException("Unknown pixel format");
|
|
||||||
}
|
|
||||||
|
|
||||||
return format;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,17 +152,13 @@ namespace Greenshot.Gfx
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
TPixelLayout empty = default;
|
TPixelLayout empty = default;
|
||||||
switch (empty)
|
return empty switch
|
||||||
{
|
{
|
||||||
case Bgr24 _:
|
Bgr24 _ => PixelFormats.Bgr24,
|
||||||
return PixelFormats.Bgr24;
|
Bgra32 _ => PixelFormats.Bgra32,
|
||||||
case Bgra32 _:
|
Bgr32 _ => PixelFormats.Bgr32,
|
||||||
return PixelFormats.Bgra32;
|
_ => throw new NotSupportedException("Unknown pixel format")
|
||||||
case Bgr32 _:
|
};
|
||||||
return PixelFormats.Bgr32;
|
|
||||||
default:
|
|
||||||
throw new NotSupportedException("Unknown pixel format");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using BenchmarkDotNet.Attributes;
|
using BenchmarkDotNet.Attributes;
|
||||||
using Dapplo.Log;
|
using Dapplo.Log;
|
||||||
|
@ -75,8 +74,7 @@ namespace Greenshot.PerformanceTests
|
||||||
//[Benchmark]
|
//[Benchmark]
|
||||||
public void Capture()
|
public void Capture()
|
||||||
{
|
{
|
||||||
using (var capture = WindowCapture.CaptureScreen())
|
using var capture = WindowCapture.CaptureScreen();
|
||||||
{
|
|
||||||
if (capture.Bitmap == null)
|
if (capture.Bitmap == null)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
|
@ -86,7 +84,6 @@ namespace Greenshot.PerformanceTests
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Capture the screen with buffered settings
|
/// Capture the screen with buffered settings
|
||||||
|
|
|
@ -40,12 +40,10 @@ namespace Greenshot.PerformanceTests
|
||||||
{
|
{
|
||||||
_unmanagedTestBitmap = new UnmanagedBitmap<Bgr32>(400, 400);
|
_unmanagedTestBitmap = new UnmanagedBitmap<Bgr32>(400, 400);
|
||||||
_unmanagedTestBitmap.Span.Fill(new Bgr32 { B = 255, G = 255, R = 255, Unused = 0});
|
_unmanagedTestBitmap.Span.Fill(new Bgr32 { B = 255, G = 255, R = 255, Unused = 0});
|
||||||
using (var graphics = Graphics.FromImage(_unmanagedTestBitmap.NativeBitmap))
|
using var graphics = Graphics.FromImage(_unmanagedTestBitmap.NativeBitmap);
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
{
|
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[GlobalCleanup]
|
[GlobalCleanup]
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -60,20 +58,17 @@ namespace Greenshot.PerformanceTests
|
||||||
[Arguments(PixelFormat.Format32bppArgb)]
|
[Arguments(PixelFormat.Format32bppArgb)]
|
||||||
public void WuQuantizer(PixelFormat pixelFormat)
|
public void WuQuantizer(PixelFormat pixelFormat)
|
||||||
{
|
{
|
||||||
using (var bitmap = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White))
|
using var bitmap = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White);
|
||||||
{
|
|
||||||
using (var graphics = Graphics.FromImage(bitmap.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmap.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
var quantizer = new WuQuantizer(bitmap);
|
var quantizer = new WuQuantizer(bitmap);
|
||||||
using (var quantizedImage = quantizer.GetQuantizedImage())
|
using var quantizedImage = quantizer.GetQuantizedImage();
|
||||||
{
|
|
||||||
quantizedImage.NativeBitmap.Save(@"quantized.png", ImageFormat.Png);
|
quantizedImage.NativeBitmap.Save(@"quantized.png", ImageFormat.Png);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
[Benchmark]
|
||||||
[Arguments(PixelFormat.Format24bppRgb)]
|
[Arguments(PixelFormat.Format24bppRgb)]
|
||||||
|
@ -81,46 +76,42 @@ namespace Greenshot.PerformanceTests
|
||||||
[Arguments(PixelFormat.Format32bppArgb)]
|
[Arguments(PixelFormat.Format32bppArgb)]
|
||||||
public void Blur_FastBitmap(PixelFormat pixelFormat)
|
public void Blur_FastBitmap(PixelFormat pixelFormat)
|
||||||
{
|
{
|
||||||
using (var bitmap = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White))
|
using var bitmap = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White);
|
||||||
{
|
|
||||||
using (var graphics = Graphics.FromImage(bitmap.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmap.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap.ApplyBoxBlur(10);
|
bitmap.ApplyBoxBlur(10);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
[Benchmark]
|
||||||
public void Blur_UnmanagedBitmap()
|
public void Blur_UnmanagedBitmap()
|
||||||
{
|
{
|
||||||
using (var unmanagedBitmap = new UnmanagedBitmap<Bgr32>(400, 400))
|
using var unmanagedBitmap = new UnmanagedBitmap<Bgr32>(400, 400);
|
||||||
{
|
|
||||||
unmanagedBitmap.Span.Fill(new Bgr32 { B = 255, G = 255, R = 255 });
|
unmanagedBitmap.Span.Fill(new Bgr32 { B = 255, G = 255, R = 255 });
|
||||||
using (var graphics = Graphics.FromImage(unmanagedBitmap.NativeBitmap))
|
using (var graphics = Graphics.FromImage(unmanagedBitmap.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
unmanagedBitmap.ApplyBoxBlur(10);
|
unmanagedBitmap.ApplyBoxBlur(10);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
[Benchmark]
|
||||||
public void Blur_Old()
|
public void Blur_Old()
|
||||||
{
|
{
|
||||||
using (var bitmap = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format32bppRgb, Color.White))
|
using var bitmap = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format32bppRgb, Color.White);
|
||||||
{
|
|
||||||
using (var graphics = Graphics.FromImage(bitmap.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmap.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxBlurOld.ApplyOldBoxBlur(bitmap, 10);
|
BoxBlurOld.ApplyOldBoxBlur(bitmap, 10);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
[Benchmark]
|
||||||
public void Scale2x_FastBitmap()
|
public void Scale2x_FastBitmap()
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
|
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
|
||||||
<PackageReference Include="CommandLineParser" Version="2.6.0" />
|
<PackageReference Include="CommandLineParser" Version="2.6.0" />
|
||||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.0.0" />
|
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.0" />
|
||||||
<PackageReference Include="SharpAvi" Version="2.1.2" />
|
<PackageReference Include="SharpAvi" Version="2.1.2" />
|
||||||
<PackageReference Include="System.Memory" Version="4.5.3" />
|
<PackageReference Include="System.Memory" Version="4.5.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -37,49 +37,50 @@ namespace Greenshot.Tests
|
||||||
[InlineData(PixelFormat.Format32bppArgb)]
|
[InlineData(PixelFormat.Format32bppArgb)]
|
||||||
public void Test_Blur(PixelFormat pixelFormat)
|
public void Test_Blur(PixelFormat pixelFormat)
|
||||||
{
|
{
|
||||||
using (var bitmapNew = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White))
|
using var bitmapNew = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White);
|
||||||
using (var bitmapOld = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White))
|
using var bitmapOld = BitmapFactory.CreateEmpty(400, 400, pixelFormat, Color.White);
|
||||||
{
|
|
||||||
using (var graphics = Graphics.FromImage(bitmapNew.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmapNew.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
bitmapNew.ApplyBoxBlur(10);
|
bitmapNew.ApplyBoxBlur(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var graphics = Graphics.FromImage(bitmapOld.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmapOld.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
BoxBlurOld.ApplyOldBoxBlur(bitmapOld, 10);
|
BoxBlurOld.ApplyOldBoxBlur(bitmapOld, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmapOld.NativeBitmap.Save(@"old.png", ImageFormat.Png);
|
bitmapOld.NativeBitmap.Save(@"old.png", ImageFormat.Png);
|
||||||
bitmapNew.NativeBitmap.Save(@"new.png", ImageFormat.Png);
|
bitmapNew.NativeBitmap.Save(@"new.png", ImageFormat.Png);
|
||||||
|
|
||||||
Assert.True(bitmapOld.IsEqualTo(bitmapNew), "New blur doesn't compare to old.");
|
Assert.True(bitmapOld.IsEqualTo(bitmapNew), "New blur doesn't compare to old.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Test_Blur_UnmanagedBitmap()
|
public void Test_Blur_UnmanagedBitmap()
|
||||||
{
|
{
|
||||||
using (var bitmapNew = new UnmanagedBitmap<Bgr32>(400, 400))
|
using var bitmapNew = new UnmanagedBitmap<Bgr32>(400, 400);
|
||||||
using (var bitmapOld = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format32bppRgb, Color.White))
|
using var bitmapOld = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format32bppRgb, Color.White);
|
||||||
{
|
|
||||||
using (var graphics = Graphics.FromImage(bitmapOld.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmapOld.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxBlurOld.ApplyOldBoxBlur(bitmapOld, 10);
|
BoxBlurOld.ApplyOldBoxBlur(bitmapOld, 10);
|
||||||
bitmapOld.NativeBitmap.Save(@"old.png", ImageFormat.Png);
|
bitmapOld.NativeBitmap.Save(@"old.png", ImageFormat.Png);
|
||||||
|
|
||||||
bitmapNew.Span.Fill(new Bgr32 { B = 255, G = 255, R = 255 });
|
bitmapNew.Span.Fill(new Bgr32 { B = 255, G = 255, R = 255 });
|
||||||
using (var graphics = Graphics.FromImage(bitmapNew.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmapNew.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmapNew.ApplyBoxBlur(10);
|
bitmapNew.ApplyBoxBlur(10);
|
||||||
bitmapNew.NativeBitmap.Save(@"new.png", ImageFormat.Png);
|
bitmapNew.NativeBitmap.Save(@"new.png", ImageFormat.Png);
|
||||||
|
|
||||||
|
@ -87,4 +88,3 @@ namespace Greenshot.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -86,8 +86,7 @@ namespace Greenshot.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Test_GdiScreenCapture()
|
public void Test_GdiScreenCapture()
|
||||||
{
|
{
|
||||||
using (var gdiScreenCapture = new GdiScreenCapture())
|
using var gdiScreenCapture = new GdiScreenCapture();
|
||||||
{
|
|
||||||
gdiScreenCapture.CaptureFrame();
|
gdiScreenCapture.CaptureFrame();
|
||||||
using (var bitmap = gdiScreenCapture.CurrentFrameAsBitmap())
|
using (var bitmap = gdiScreenCapture.CurrentFrameAsBitmap())
|
||||||
{
|
{
|
||||||
|
@ -107,7 +106,6 @@ namespace Greenshot.Tests
|
||||||
|
|
||||||
gdiScreenCapture.CaptureFrame();
|
gdiScreenCapture.CaptureFrame();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test if a capture from a window works
|
/// Test if a capture from a window works
|
||||||
|
@ -144,11 +142,12 @@ namespace Greenshot.Tests
|
||||||
var template = new SimpleTemplate();
|
var template = new SimpleTemplate();
|
||||||
var bitmapSource = template.Apply(capture).ToBitmapSource();
|
var bitmapSource = template.Apply(capture).ToBitmapSource();
|
||||||
using (var outputStream = bitmapSource.ToStream(OutputFormats.png))
|
using (var outputStream = bitmapSource.ToStream(OutputFormats.png))
|
||||||
using (var fileStream = File.Create("Test_CaptureFlow_DwmWindowSource.png"))
|
|
||||||
{
|
{
|
||||||
|
using var fileStream = File.Create("Test_CaptureFlow_DwmWindowSource.png");
|
||||||
outputStream.Seek(0, SeekOrigin.Begin);
|
outputStream.Seek(0, SeekOrigin.Begin);
|
||||||
await outputStream.CopyToAsync(fileStream);
|
await outputStream.CopyToAsync(fileStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.Equal(bounds.Size, bitmapSource.Size());
|
Assert.Equal(bounds.Size, bitmapSource.Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,8 +158,7 @@ namespace Greenshot.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Test_BitmapCapture()
|
public void Test_BitmapCapture()
|
||||||
{
|
{
|
||||||
using (var screenBitmapCapture = new BitmapScreenCapture())
|
using var screenBitmapCapture = new BitmapScreenCapture();
|
||||||
{
|
|
||||||
screenBitmapCapture.CaptureFrame();
|
screenBitmapCapture.CaptureFrame();
|
||||||
|
|
||||||
Assert.NotNull(screenBitmapCapture.CurrentFrameAsBitmap());
|
Assert.NotNull(screenBitmapCapture.CurrentFrameAsBitmap());
|
||||||
|
@ -169,8 +167,7 @@ namespace Greenshot.Tests
|
||||||
screenBitmapCapture.CurrentFrameAsBitmap().NativeBitmap.Save(testFile1, ImageFormat.Png);
|
screenBitmapCapture.CurrentFrameAsBitmap().NativeBitmap.Save(testFile1, ImageFormat.Png);
|
||||||
|
|
||||||
var testFile2 = Path.Combine(Path.GetTempPath(), @"test-bitmapsource.png");
|
var testFile2 = Path.Combine(Path.GetTempPath(), @"test-bitmapsource.png");
|
||||||
using (var fileStream = new FileStream(testFile2, FileMode.Create))
|
using var fileStream = new FileStream(testFile2, FileMode.Create);
|
||||||
{
|
|
||||||
var encoder = new PngBitmapEncoder
|
var encoder = new PngBitmapEncoder
|
||||||
{
|
{
|
||||||
Interlace = PngInterlaceOption.Off
|
Interlace = PngInterlaceOption.Off
|
||||||
|
@ -180,5 +177,3 @@ namespace Greenshot.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,27 +19,27 @@ namespace Greenshot.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestBlur()
|
public void TestBlur()
|
||||||
{
|
{
|
||||||
using (var bitmap1 = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format24bppRgb, Color.White))
|
using var bitmap1 = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format24bppRgb, Color.White);
|
||||||
using (var bitmap2 = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format24bppRgb, Color.White))
|
using var bitmap2 = BitmapFactory.CreateEmpty(400, 400, PixelFormat.Format24bppRgb, Color.White);
|
||||||
{
|
|
||||||
using (var graphics = Graphics.FromImage(bitmap1.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmap1.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap1.NativeBitmap.Save("bitmap0.png", ImageFormat.Png);
|
bitmap1.NativeBitmap.Save("bitmap0.png", ImageFormat.Png);
|
||||||
bitmap1.ApplyBoxBlur(10);
|
bitmap1.ApplyBoxBlur(10);
|
||||||
bitmap1.NativeBitmap.Save("bitmap1.png", ImageFormat.Png);
|
bitmap1.NativeBitmap.Save("bitmap1.png", ImageFormat.Png);
|
||||||
|
|
||||||
using (var graphics = Graphics.FromImage(bitmap2.NativeBitmap))
|
using (var graphics = Graphics.FromImage(bitmap2.NativeBitmap))
|
||||||
using (var pen = new SolidBrush(Color.Blue))
|
|
||||||
{
|
{
|
||||||
|
using var pen = new SolidBrush(Color.Blue);
|
||||||
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
graphics.FillRectangle(pen, new Rectangle(30, 30, 340, 340));
|
||||||
}
|
}
|
||||||
|
|
||||||
BoxBlurOld.ApplyOldBoxBlur(bitmap2, 10);
|
BoxBlurOld.ApplyOldBoxBlur(bitmap2, 10);
|
||||||
bitmap2.NativeBitmap.Save("bitmap2.png", ImageFormat.Png);
|
bitmap2.NativeBitmap.Save("bitmap2.png", ImageFormat.Png);
|
||||||
Assert.True(bitmap1.IsEqualTo(bitmap2));
|
Assert.True(bitmap1.IsEqualTo(bitmap2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
|
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
|
||||||
<PackageReference Include="CommandLineParser" Version="2.6.0" />
|
<PackageReference Include="CommandLineParser" Version="2.6.0" />
|
||||||
<PackageReference Include="Dapplo.Log.XUnit" Version="1.3.26" />
|
<PackageReference Include="Dapplo.Log.XUnit" Version="1.3.26" />
|
||||||
<PackageReference Include="Dapplo.Windows" Version="0.11.6" />
|
<PackageReference Include="Dapplo.Windows" Version="0.11.6" />
|
||||||
|
|
|
@ -18,11 +18,9 @@ namespace Greenshot.Tests.Implementation
|
||||||
public static void ApplyOldBoxBlur(this IBitmapWithNativeSupport destinationBitmap, int range)
|
public static void ApplyOldBoxBlur(this IBitmapWithNativeSupport destinationBitmap, int range)
|
||||||
{
|
{
|
||||||
// We only need one fastbitmap as we use it as source and target (the reading is done for one line H/V, writing after "parsing" one line H/V)
|
// We only need one fastbitmap as we use it as source and target (the reading is done for one line H/V, writing after "parsing" one line H/V)
|
||||||
using (var fastBitmap = FastBitmapFactory.Create(destinationBitmap))
|
using var fastBitmap = FastBitmapFactory.Create(destinationBitmap);
|
||||||
{
|
|
||||||
fastBitmap.ApplyOldBoxBlur(range);
|
fastBitmap.ApplyOldBoxBlur(range);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply BoxBlur to the fastBitmap
|
/// Apply BoxBlur to the fastBitmap
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue