mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 14:03:23 -07:00
#315 made sure that with a small capture the canvas is enlarged so OCR can still work.
This commit is contained in:
parent
5935a435b5
commit
fa0ed4a53b
1 changed files with 36 additions and 1 deletions
|
@ -27,6 +27,8 @@ using Windows.Graphics.Imaging;
|
||||||
using Windows.Media.Ocr;
|
using Windows.Media.Ocr;
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
|
using Greenshot.Base.Core.Enums;
|
||||||
|
using Greenshot.Base.Effects;
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Ocr;
|
using Greenshot.Base.Interfaces.Ocr;
|
||||||
using Greenshot.Base.Interfaces.Plugin;
|
using Greenshot.Base.Interfaces.Plugin;
|
||||||
|
@ -39,6 +41,8 @@ namespace Greenshot.Plugin.Win10
|
||||||
public class Win10OcrProvider : IOcrProvider
|
public class Win10OcrProvider : IOcrProvider
|
||||||
{
|
{
|
||||||
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrProvider));
|
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrProvider));
|
||||||
|
private const int MinWidth = 130;
|
||||||
|
private const int MinHeight = 130;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor, this is only debug information
|
/// Constructor, this is only debug information
|
||||||
|
@ -62,7 +66,38 @@ namespace Greenshot.Plugin.Win10
|
||||||
OcrInformation result;
|
OcrInformation result;
|
||||||
using (var imageStream = new MemoryStream())
|
using (var imageStream = new MemoryStream())
|
||||||
{
|
{
|
||||||
ImageOutput.SaveToStream(surface, imageStream, new SurfaceOutputSettings());
|
// We only want the background
|
||||||
|
var outputSettings = new SurfaceOutputSettings(OutputFormat.png, 0, true)
|
||||||
|
{
|
||||||
|
ReduceColors = true,
|
||||||
|
SaveBackgroundOnly = true
|
||||||
|
};
|
||||||
|
// Force Grayscale output
|
||||||
|
outputSettings.Effects.Add(new GrayscaleEffect());
|
||||||
|
if (surface.Image.Width < MinWidth || surface.Image.Height < MinHeight)
|
||||||
|
{
|
||||||
|
int addedWidth = MinWidth - surface.Image.Width;
|
||||||
|
if (addedWidth < 0)
|
||||||
|
{
|
||||||
|
addedWidth = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addedWidth /= 2;
|
||||||
|
}
|
||||||
|
int addedHeight = MinHeight - surface.Image.Height;
|
||||||
|
if (addedHeight < 0)
|
||||||
|
{
|
||||||
|
addedHeight = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addedHeight /= 2;
|
||||||
|
}
|
||||||
|
IEffect effect = new ResizeCanvasEffect(addedWidth, addedWidth, addedHeight, addedHeight);
|
||||||
|
outputSettings.Effects.Add(effect);
|
||||||
|
}
|
||||||
|
ImageOutput.SaveToStream(surface, imageStream, outputSettings);
|
||||||
imageStream.Position = 0;
|
imageStream.Position = 0;
|
||||||
var randomAccessStream = imageStream.AsRandomAccessStream();
|
var randomAccessStream = imageStream.AsRandomAccessStream();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue