mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-24 01:00:27 +12:00
Decrease unnecessary bitmap casts
This commit is contained in:
parent
f49c345ffd
commit
b8c10a7067
|
@ -224,19 +224,6 @@ public static Image ResizeImageLimit(Image img, int size)
|
|||
return ResizeImageLimit(img, size, size);
|
||||
}
|
||||
|
||||
public static Image CropImage(Image img, Rectangle rect)
|
||||
{
|
||||
if (img != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 && new Rectangle(0, 0, img.Width, img.Height).Contains(rect))
|
||||
{
|
||||
using (Bitmap bmp = new Bitmap(img))
|
||||
{
|
||||
return bmp.Clone(rect, bmp.PixelFormat);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Bitmap CropBitmap(Bitmap bmp, Rectangle rect)
|
||||
{
|
||||
if (bmp != null && rect.X >= 0 && rect.Y >= 0 && rect.Width > 0 && rect.Height > 0 && new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(rect))
|
||||
|
@ -406,12 +393,12 @@ public static Bitmap QuickAutoCropTransparent(Bitmap bmp)
|
|||
return bmp;
|
||||
}
|
||||
|
||||
public static Image AddCanvas(Image img, Padding margin)
|
||||
public static Bitmap AddCanvas(Image img, Padding margin)
|
||||
{
|
||||
return AddCanvas(img, margin, Color.Transparent);
|
||||
}
|
||||
|
||||
public static Image AddCanvas(Image img, Padding margin, Color canvasColor)
|
||||
public static Bitmap AddCanvas(Image img, Padding margin, Color canvasColor)
|
||||
{
|
||||
if (margin.All == 0 || img.Width + margin.Horizontal < 1 || img.Height + margin.Vertical < 1)
|
||||
{
|
||||
|
@ -930,7 +917,7 @@ public static Bitmap AddShadow(Image img, float opacity, int size)
|
|||
|
||||
public static Bitmap AddShadow(Image img, float opacity, int size, float darkness, Color color, Point offset)
|
||||
{
|
||||
Image shadowImage = null;
|
||||
Bitmap shadowImage = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -950,7 +937,7 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes
|
|||
|
||||
if (size > 0)
|
||||
{
|
||||
BoxBlur((Bitmap)shadowImage, size);
|
||||
BoxBlur(shadowImage, size);
|
||||
}
|
||||
|
||||
if (darkness > 1)
|
||||
|
@ -958,7 +945,7 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes
|
|||
ColorMatrix alphaMatrix = new ColorMatrix();
|
||||
alphaMatrix.Matrix33 = darkness;
|
||||
|
||||
Image shadowImage2 = alphaMatrix.Apply(shadowImage);
|
||||
Bitmap shadowImage2 = (Bitmap)alphaMatrix.Apply(shadowImage);
|
||||
shadowImage.Dispose();
|
||||
shadowImage = shadowImage2;
|
||||
}
|
||||
|
@ -981,16 +968,15 @@ public static Bitmap AddShadow(Image img, float opacity, int size, float darknes
|
|||
}
|
||||
}
|
||||
|
||||
public static Bitmap Sharpen(Image img, double strength)
|
||||
public static Bitmap Sharpen(Bitmap bmp, double strength)
|
||||
{
|
||||
using (Bitmap bitmap = (Bitmap)img)
|
||||
if (bmp != null)
|
||||
{
|
||||
if (bitmap != null)
|
||||
using (bmp)
|
||||
{
|
||||
Bitmap sharpenImage = bitmap.Clone() as Bitmap;
|
||||
|
||||
int width = img.Width;
|
||||
int height = img.Height;
|
||||
Bitmap sharpenImage = (Bitmap)bmp.Clone();
|
||||
int width = sharpenImage.Width;
|
||||
int height = sharpenImage.Height;
|
||||
|
||||
// Create sharpening filter.
|
||||
const int filterSize = 5;
|
||||
|
@ -1009,75 +995,73 @@ public static Bitmap Sharpen(Image img, double strength)
|
|||
|
||||
const int s = filterSize / 2;
|
||||
|
||||
Color[,] result = new Color[img.Width, img.Height];
|
||||
Color[,] result = new Color[sharpenImage.Width, sharpenImage.Height];
|
||||
|
||||
// Lock image bits for read/write.
|
||||
if (sharpenImage != null)
|
||||
BitmapData pbits = sharpenImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
|
||||
|
||||
// Declare an array to hold the bytes of the bitmap.
|
||||
int bytes = pbits.Stride * height;
|
||||
byte[] rgbValues = new byte[bytes];
|
||||
|
||||
// Copy the RGB values into the array.
|
||||
Marshal.Copy(pbits.Scan0, rgbValues, 0, bytes);
|
||||
|
||||
int rgb;
|
||||
// Fill the color array with the new sharpened color values.
|
||||
for (int x = s; x < width - s; x++)
|
||||
{
|
||||
BitmapData pbits = sharpenImage.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
|
||||
|
||||
// Declare an array to hold the bytes of the bitmap.
|
||||
int bytes = pbits.Stride * height;
|
||||
byte[] rgbValues = new byte[bytes];
|
||||
|
||||
// Copy the RGB values into the array.
|
||||
Marshal.Copy(pbits.Scan0, rgbValues, 0, bytes);
|
||||
|
||||
int rgb;
|
||||
// Fill the color array with the new sharpened color values.
|
||||
for (int x = s; x < width - s; x++)
|
||||
for (int y = s; y < height - s; y++)
|
||||
{
|
||||
for (int y = s; y < height - s; y++)
|
||||
{
|
||||
double red = 0.0, green = 0.0, blue = 0.0;
|
||||
double red = 0.0, green = 0.0, blue = 0.0;
|
||||
|
||||
for (int filterX = 0; filterX < filterSize; filterX++)
|
||||
for (int filterX = 0; filterX < filterSize; filterX++)
|
||||
{
|
||||
for (int filterY = 0; filterY < filterSize; filterY++)
|
||||
{
|
||||
for (int filterY = 0; filterY < filterSize; filterY++)
|
||||
{
|
||||
int imageX = (x - s + filterX + width) % width;
|
||||
int imageY = (y - s + filterY + height) % height;
|
||||
int imageX = (x - s + filterX + width) % width;
|
||||
int imageY = (y - s + filterY + height) % height;
|
||||
|
||||
rgb = (imageY * pbits.Stride) + (3 * imageX);
|
||||
rgb = (imageY * pbits.Stride) + (3 * imageX);
|
||||
|
||||
red += rgbValues[rgb + 2] * filter[filterX, filterY];
|
||||
green += rgbValues[rgb + 1] * filter[filterX, filterY];
|
||||
blue += rgbValues[rgb + 0] * filter[filterX, filterY];
|
||||
}
|
||||
|
||||
rgb = (y * pbits.Stride) + (3 * x);
|
||||
|
||||
int r = Math.Min(Math.Max((int)((factor * red) + (bias * rgbValues[rgb + 2])), 0), 255);
|
||||
int g = Math.Min(Math.Max((int)((factor * green) + (bias * rgbValues[rgb + 1])), 0), 255);
|
||||
int b = Math.Min(Math.Max((int)((factor * blue) + (bias * rgbValues[rgb + 0])), 0), 255);
|
||||
|
||||
result[x, y] = Color.FromArgb(r, g, b);
|
||||
red += rgbValues[rgb + 2] * filter[filterX, filterY];
|
||||
green += rgbValues[rgb + 1] * filter[filterX, filterY];
|
||||
blue += rgbValues[rgb + 0] * filter[filterX, filterY];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the image with the sharpened pixels.
|
||||
for (int x = s; x < width - s; x++)
|
||||
{
|
||||
for (int y = s; y < height - s; y++)
|
||||
{
|
||||
rgb = (y * pbits.Stride) + (3 * x);
|
||||
|
||||
rgbValues[rgb + 2] = result[x, y].R;
|
||||
rgbValues[rgb + 1] = result[x, y].G;
|
||||
rgbValues[rgb + 0] = result[x, y].B;
|
||||
int r = Math.Min(Math.Max((int)((factor * red) + (bias * rgbValues[rgb + 2])), 0), 255);
|
||||
int g = Math.Min(Math.Max((int)((factor * green) + (bias * rgbValues[rgb + 1])), 0), 255);
|
||||
int b = Math.Min(Math.Max((int)((factor * blue) + (bias * rgbValues[rgb + 0])), 0), 255);
|
||||
|
||||
result[x, y] = Color.FromArgb(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the RGB values back to the bitmap.
|
||||
Marshal.Copy(rgbValues, 0, pbits.Scan0, bytes);
|
||||
// Release image bits.
|
||||
sharpenImage.UnlockBits(pbits);
|
||||
}
|
||||
|
||||
// Update the image with the sharpened pixels.
|
||||
for (int x = s; x < width - s; x++)
|
||||
{
|
||||
for (int y = s; y < height - s; y++)
|
||||
{
|
||||
rgb = (y * pbits.Stride) + (3 * x);
|
||||
|
||||
rgbValues[rgb + 2] = result[x, y].R;
|
||||
rgbValues[rgb + 1] = result[x, y].G;
|
||||
rgbValues[rgb + 0] = result[x, y].B;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the RGB values back to the bitmap.
|
||||
Marshal.Copy(rgbValues, 0, pbits.Scan0, bytes);
|
||||
// Release image bits.
|
||||
sharpenImage.UnlockBits(pbits);
|
||||
|
||||
return sharpenImage;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1634,7 +1618,7 @@ public static string SaveImageFileDialog(Image img, string filePath = "", bool u
|
|||
{
|
||||
sfd.Filter = "PNG (*.png)|*.png|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|GIF (*.gif)|*.gif|BMP (*.bmp)|*.bmp|TIFF (*.tif, *.tiff)|*.tif;*.tiff";
|
||||
sfd.DefaultExt = "png";
|
||||
|
||||
|
||||
string initialDirectory = null;
|
||||
|
||||
if (useLastDirectory && !string.IsNullOrEmpty(HelpersOptions.LastSaveDirectory) && Directory.Exists(HelpersOptions.LastSaveDirectory))
|
||||
|
|
|
@ -59,7 +59,7 @@ public override Image Apply(Image img)
|
|||
{
|
||||
if (Margin.All == 0) return img;
|
||||
|
||||
return ImageHelpers.CropImage(img, new Rectangle(Margin.Left, Margin.Top, img.Width - Margin.Horizontal, img.Height - Margin.Vertical));
|
||||
return ImageHelpers.CropBitmap((Bitmap)img, new Rectangle(Margin.Left, Margin.Top, img.Width - Margin.Horizontal, img.Height - Margin.Vertical));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1285,7 +1285,7 @@ internal void UpdateRegionPath()
|
|||
}
|
||||
}
|
||||
|
||||
public Image GetResultImage()
|
||||
public Bitmap GetResultImage()
|
||||
{
|
||||
if (IsEditorMode)
|
||||
{
|
||||
|
@ -1304,9 +1304,9 @@ public Image GetResultImage()
|
|||
gp = regionFillPath;
|
||||
}
|
||||
|
||||
using (Image img = RegionCaptureTasks.ApplyRegionPathToImage(Canvas, gp, out Rectangle rect))
|
||||
using (Bitmap bmp = RegionCaptureTasks.ApplyRegionPathToImage(Canvas, gp, out Rectangle rect))
|
||||
{
|
||||
return ShapeManager.RenderOutputImage(img, rect.Location);
|
||||
return ShapeManager.RenderOutputImage(bmp, rect.Location);
|
||||
}
|
||||
}
|
||||
else if (Result == RegionResult.Fullscreen)
|
||||
|
@ -1322,9 +1322,9 @@ public Image GetResultImage()
|
|||
Screen screen = screens[MonitorIndex];
|
||||
Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds);
|
||||
|
||||
using (Image img = ShapeManager.RenderOutputImage(Canvas))
|
||||
using (Bitmap bmp = ShapeManager.RenderOutputImage(Canvas))
|
||||
{
|
||||
return ImageHelpers.CropImage(img, screenRect);
|
||||
return ImageHelpers.CropBitmap(bmp, screenRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1332,9 +1332,9 @@ public Image GetResultImage()
|
|||
{
|
||||
Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based();
|
||||
|
||||
using (Image img = ShapeManager.RenderOutputImage(Canvas))
|
||||
using (Bitmap bmp = ShapeManager.RenderOutputImage(Canvas))
|
||||
{
|
||||
return ImageHelpers.CropImage(img, activeScreenRect);
|
||||
return ImageHelpers.CropBitmap(bmp, activeScreenRect);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ private void RectangleLight_MouseUp(object sender, MouseEventArgs e)
|
|||
}
|
||||
}
|
||||
|
||||
public Image GetAreaImage()
|
||||
public Bitmap GetAreaImage()
|
||||
{
|
||||
Rectangle rect = SelectionRectangle0Based;
|
||||
|
||||
|
@ -170,10 +170,10 @@ public Image GetAreaImage()
|
|||
{
|
||||
if (rect.X == 0 && rect.Y == 0 && rect.Width == backgroundImage.Width && rect.Height == backgroundImage.Height)
|
||||
{
|
||||
return (Image)backgroundImage.Clone();
|
||||
return (Bitmap)backgroundImage.Clone();
|
||||
}
|
||||
|
||||
return ImageHelpers.CropImage(backgroundImage, rect);
|
||||
return ImageHelpers.CropBitmap(backgroundImage, rect);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -45,7 +45,7 @@ public partial class ScrollingCaptureForm : Form
|
|||
|
||||
private WindowInfo selectedWindow;
|
||||
private Rectangle selectedRectangle;
|
||||
private List<Image> images = new List<Image>();
|
||||
private List<Bitmap> images = new List<Bitmap>();
|
||||
private int currentScrollCount;
|
||||
private bool isBusy, isCapturing, firstCapture, detectingScrollMethod;
|
||||
private ScrollingCaptureScrollMethod currentScrollMethod;
|
||||
|
@ -244,11 +244,11 @@ private void Clean()
|
|||
|
||||
if (images != null)
|
||||
{
|
||||
foreach (Image image in images)
|
||||
foreach (Bitmap bmp in images)
|
||||
{
|
||||
if (image != null)
|
||||
if (bmp != null)
|
||||
{
|
||||
image.Dispose();
|
||||
bmp.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,13 +279,13 @@ private void RemoveDuplicates()
|
|||
{
|
||||
for (int i = images.Count - 1; i > 0; i--)
|
||||
{
|
||||
bool result = ImageHelpers.IsImagesEqual((Bitmap)images[i], (Bitmap)images[i - 1]);
|
||||
bool result = ImageHelpers.IsImagesEqual(images[i], images[i - 1]);
|
||||
|
||||
if (result)
|
||||
{
|
||||
Image img = images[i];
|
||||
images.Remove(img);
|
||||
img.Dispose();
|
||||
Bitmap bmp = images[i];
|
||||
images.Remove(bmp);
|
||||
bmp.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,11 +315,11 @@ private void captureTimer_Tick(object sender, EventArgs e)
|
|||
}
|
||||
|
||||
Screenshot screenshot = new Screenshot() { CaptureCursor = false };
|
||||
Image image = screenshot.CaptureRectangle(selectedRectangle);
|
||||
Bitmap bmp = screenshot.CaptureRectangle(selectedRectangle);
|
||||
|
||||
if (image != null)
|
||||
if (bmp != null)
|
||||
{
|
||||
images.Add(image);
|
||||
images.Add(bmp);
|
||||
}
|
||||
|
||||
if (Options.ScrollMethod == ScrollingCaptureScrollMethod.Automatic && detectingScrollMethod && images.Count > 1 && IsLastTwoImagesSame())
|
||||
|
@ -433,11 +433,11 @@ private bool IsLastTwoImagesSame()
|
|||
|
||||
if (images.Count > 1)
|
||||
{
|
||||
result = ImageHelpers.IsImagesEqual((Bitmap)images[images.Count - 1], (Bitmap)images[images.Count - 2]);
|
||||
result = ImageHelpers.IsImagesEqual(images[images.Count - 1], images[images.Count - 2]);
|
||||
|
||||
if (result)
|
||||
{
|
||||
Image last = images[images.Count - 1];
|
||||
Bitmap last = images[images.Count - 1];
|
||||
images.Remove(last);
|
||||
last.Dispose();
|
||||
}
|
||||
|
@ -571,15 +571,15 @@ private Image CombineImages()
|
|||
|
||||
if (images.Count == 1)
|
||||
{
|
||||
return (Image)images[0].Clone();
|
||||
return (Bitmap)images[0].Clone();
|
||||
}
|
||||
|
||||
List<Image> output = new List<Image>();
|
||||
List<Bitmap> output = new List<Bitmap>();
|
||||
|
||||
for (int i = 0; i < images.Count - Options.IgnoreLast; i++)
|
||||
{
|
||||
Image newImage;
|
||||
Image image = images[i];
|
||||
Bitmap newImage;
|
||||
Bitmap image = images[i];
|
||||
|
||||
if (Options.TrimLeftEdge > 0 || Options.TrimTopEdge > 0 || Options.TrimRightEdge > 0 || Options.TrimBottomEdge > 0 ||
|
||||
Options.CombineAdjustmentVertical > 0 || Options.CombineAdjustmentLastVertical > 0)
|
||||
|
@ -598,7 +598,7 @@ private Image CombineImages()
|
|||
rect.Height -= Options.CombineAdjustmentVertical;
|
||||
}
|
||||
|
||||
newImage = ImageHelpers.CropImage(image, rect);
|
||||
newImage = ImageHelpers.CropBitmap(image, rect);
|
||||
|
||||
if (newImage == null)
|
||||
{
|
||||
|
@ -607,7 +607,7 @@ private Image CombineImages()
|
|||
}
|
||||
else
|
||||
{
|
||||
newImage = (Image)image.Clone();
|
||||
newImage = (Bitmap)image.Clone();
|
||||
}
|
||||
|
||||
output.Add(newImage);
|
||||
|
@ -615,7 +615,7 @@ private Image CombineImages()
|
|||
|
||||
Image result = ImageHelpers.CombineImages(output);
|
||||
|
||||
foreach (Image image in output)
|
||||
foreach (Bitmap image in output)
|
||||
{
|
||||
if (image != null)
|
||||
{
|
||||
|
@ -664,13 +664,13 @@ private void chkAutoUpload_CheckedChanged(object sender, EventArgs e)
|
|||
Options.AutoUpload = chkAutoUpload.Checked;
|
||||
}
|
||||
|
||||
private Padding GuessEdges(Image img1, Image img2)
|
||||
private Padding GuessEdges(Bitmap img1, Bitmap img2)
|
||||
{
|
||||
Padding result = new Padding();
|
||||
Rectangle rect = new Rectangle(0, 0, img1.Width, img1.Height);
|
||||
|
||||
using (UnsafeBitmap bmp1 = new UnsafeBitmap((Bitmap)img1, true, ImageLockMode.ReadOnly))
|
||||
using (UnsafeBitmap bmp2 = new UnsafeBitmap((Bitmap)img2, true, ImageLockMode.ReadOnly))
|
||||
using (UnsafeBitmap bmp1 = new UnsafeBitmap(img1, true, ImageLockMode.ReadOnly))
|
||||
using (UnsafeBitmap bmp2 = new UnsafeBitmap(img2, true, ImageLockMode.ReadOnly))
|
||||
{
|
||||
bool valueFound = false;
|
||||
|
||||
|
@ -761,7 +761,7 @@ private void GuessCombineAdjustments()
|
|||
}
|
||||
}
|
||||
|
||||
private int CalculateVerticalOffset(Image img1, Image img2, int ignoreRightOffset = 50)
|
||||
private int CalculateVerticalOffset(Bitmap img1, Bitmap img2, int ignoreRightOffset = 50)
|
||||
{
|
||||
int lastMatchCount = 0;
|
||||
int lastMatchOffset = 0;
|
||||
|
@ -770,8 +770,8 @@ private int CalculateVerticalOffset(Image img1, Image img2, int ignoreRightOffse
|
|||
img1.Width - Options.TrimLeftEdge - Options.TrimRightEdge - (img1.Width > ignoreRightOffset ? ignoreRightOffset : 0),
|
||||
img1.Height - Options.TrimTopEdge - Options.TrimBottomEdge);
|
||||
|
||||
using (UnsafeBitmap bmp1 = new UnsafeBitmap((Bitmap)img1, true, ImageLockMode.ReadOnly))
|
||||
using (UnsafeBitmap bmp2 = new UnsafeBitmap((Bitmap)img2, true, ImageLockMode.ReadOnly))
|
||||
using (UnsafeBitmap bmp1 = new UnsafeBitmap(img1, true, ImageLockMode.ReadOnly))
|
||||
using (UnsafeBitmap bmp2 = new UnsafeBitmap(img2, true, ImageLockMode.ReadOnly))
|
||||
{
|
||||
for (int y = rect.Y; y < rect.Bottom; y++)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace ShareX.ScreenCaptureLib
|
|||
{
|
||||
public static class RegionCaptureTasks
|
||||
{
|
||||
public static Image GetRegionImage(RegionCaptureOptions options)
|
||||
public static Bitmap GetRegionImage(RegionCaptureOptions options)
|
||||
{
|
||||
RegionCaptureOptions newOptions = GetRegionCaptureOptions(options);
|
||||
|
||||
|
@ -158,9 +158,9 @@ public static void ShowScreenRuler(RegionCaptureOptions options)
|
|||
}
|
||||
}
|
||||
|
||||
public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp, out Rectangle resultArea)
|
||||
public static Bitmap ApplyRegionPathToImage(Bitmap bmp, GraphicsPath gp, out Rectangle resultArea)
|
||||
{
|
||||
if (img != null && gp != null)
|
||||
if (bmp != null && gp != null)
|
||||
{
|
||||
Rectangle regionArea = Rectangle.Round(gp.GetBounds());
|
||||
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
|
||||
|
@ -168,16 +168,16 @@ public static Image ApplyRegionPathToImage(Image img, GraphicsPath gp, out Recta
|
|||
|
||||
if (resultArea.IsValid())
|
||||
{
|
||||
using (Bitmap bmp = img.CreateEmptyBitmap())
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
using (TextureBrush brush = new TextureBrush(img))
|
||||
using (Bitmap bmpResult = bmp.CreateEmptyBitmap())
|
||||
using (Graphics g = Graphics.FromImage(bmpResult))
|
||||
using (TextureBrush brush = new TextureBrush(bmp))
|
||||
{
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
|
||||
g.FillPath(brush, gp);
|
||||
|
||||
return ImageHelpers.CropBitmap(bmp, resultArea);
|
||||
return ImageHelpers.CropBitmap(bmpResult, resultArea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,17 +93,17 @@ public Image CaptureWindowTransparent(IntPtr handle)
|
|||
Thread.Sleep(10);
|
||||
Application.DoEvents();
|
||||
|
||||
whiteBackground = (Bitmap)CaptureRectangleNative(rect);
|
||||
whiteBackground = CaptureRectangleNative(rect);
|
||||
|
||||
form.BackColor = Color.Black;
|
||||
Application.DoEvents();
|
||||
|
||||
blackBackground = (Bitmap)CaptureRectangleNative(rect);
|
||||
blackBackground = CaptureRectangleNative(rect);
|
||||
|
||||
form.BackColor = Color.White;
|
||||
Application.DoEvents();
|
||||
|
||||
whiteBackground2 = (Bitmap)CaptureRectangleNative(rect);
|
||||
whiteBackground2 = CaptureRectangleNative(rect);
|
||||
|
||||
form.Close();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public abstract class BaseEffectShape : BaseShape
|
|||
public abstract string OverlayText { get; }
|
||||
|
||||
private bool drawCache, isEffectCaching, isCachePending, isDisposePending;
|
||||
private Image cachedEffect;
|
||||
private Bitmap cachedEffect;
|
||||
|
||||
public abstract void ApplyEffect(Bitmap bmp);
|
||||
|
||||
|
@ -155,7 +155,7 @@ private void CacheEffect()
|
|||
|
||||
Task.Run(() =>
|
||||
{
|
||||
ApplyEffect((Bitmap)cachedEffect);
|
||||
ApplyEffect(cachedEffect);
|
||||
|
||||
isEffectCaching = false;
|
||||
|
||||
|
|
|
@ -1261,14 +1261,14 @@ public WindowInfo FindSelectedWindowInfo(Point position)
|
|||
return null;
|
||||
}
|
||||
|
||||
public Image RenderOutputImage(Image img)
|
||||
public Bitmap RenderOutputImage(Bitmap bmp)
|
||||
{
|
||||
return RenderOutputImage(img, Point.Empty);
|
||||
return RenderOutputImage(bmp, Point.Empty);
|
||||
}
|
||||
|
||||
public Image RenderOutputImage(Image img, Point offset)
|
||||
public Bitmap RenderOutputImage(Bitmap bmp, Point offset)
|
||||
{
|
||||
Bitmap bmp = new Bitmap(img);
|
||||
Bitmap bmpOutput = (Bitmap)bmp.Clone();
|
||||
|
||||
if (DrawingShapes.Length > 0 || EffectShapes.Length > 0)
|
||||
{
|
||||
|
@ -1277,13 +1277,13 @@ public Image RenderOutputImage(Image img, Point offset)
|
|||
|
||||
MoveAll(-offset.X, -offset.Y);
|
||||
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
using (Graphics g = Graphics.FromImage(bmpOutput))
|
||||
{
|
||||
foreach (BaseEffectShape shape in EffectShapes)
|
||||
{
|
||||
if (shape != null)
|
||||
{
|
||||
shape.OnDrawFinal(g, bmp);
|
||||
shape.OnDrawFinal(g, bmpOutput);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1302,7 +1302,7 @@ public Image RenderOutputImage(Image img, Point offset)
|
|||
IsRenderingOutput = false;
|
||||
}
|
||||
|
||||
return bmp;
|
||||
return bmpOutput;
|
||||
}
|
||||
|
||||
private void SelectShape(BaseShape shape)
|
||||
|
@ -1787,7 +1787,7 @@ private void InsertImageFile()
|
|||
|
||||
private void InsertImageFromScreen()
|
||||
{
|
||||
Image img;
|
||||
Bitmap bmp;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -1796,7 +1796,7 @@ private void InsertImageFromScreen()
|
|||
menuForm.Hide();
|
||||
Thread.Sleep(250);
|
||||
|
||||
img = RegionCaptureTasks.GetRegionImage(Options);
|
||||
bmp = RegionCaptureTasks.GetRegionImage(Options);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -1805,7 +1805,7 @@ private void InsertImageFromScreen()
|
|||
Form.Resume();
|
||||
}
|
||||
|
||||
InsertImage(img);
|
||||
InsertImage(bmp);
|
||||
}
|
||||
|
||||
private void InsertImage(Image img)
|
||||
|
@ -1905,7 +1905,7 @@ private void ChangeCanvasSize()
|
|||
if (canvasSizeForm.ShowDialog(Form) == DialogResult.OK)
|
||||
{
|
||||
Padding canvas = canvasSizeForm.Canvas;
|
||||
Bitmap bmp = (Bitmap)ImageHelpers.AddCanvas(Form.Canvas, canvas, Options.EditorCanvasColor);
|
||||
Bitmap bmp = ImageHelpers.AddCanvas(Form.Canvas, canvas, Options.EditorCanvasColor);
|
||||
|
||||
if (bmp != null)
|
||||
{
|
||||
|
@ -1933,7 +1933,7 @@ public void AutoResizeCanvas()
|
|||
|
||||
private void ChangeCanvasSize(Padding margin, Color canvasColor)
|
||||
{
|
||||
Bitmap bmp = (Bitmap)ImageHelpers.AddCanvas(Form.Canvas, margin, canvasColor);
|
||||
Bitmap bmp = ImageHelpers.AddCanvas(Form.Canvas, margin, canvasColor);
|
||||
|
||||
if (bmp != null)
|
||||
{
|
||||
|
|
|
@ -39,10 +39,10 @@ protected override ImageInfo Execute(TaskSettings taskSettings)
|
|||
case RegionCaptureType.Default:
|
||||
if (RegionCaptureForm.LastRegionFillPath != null)
|
||||
{
|
||||
using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
|
||||
using (Bitmap screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
|
||||
{
|
||||
Image img = RegionCaptureTasks.ApplyRegionPathToImage(screenshot, RegionCaptureForm.LastRegionFillPath, out _);
|
||||
return new ImageInfo(img);
|
||||
Bitmap bmp = RegionCaptureTasks.ApplyRegionPathToImage(screenshot, RegionCaptureForm.LastRegionFillPath, out _);
|
||||
return new ImageInfo(bmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -52,10 +52,10 @@ protected override ImageInfo Execute(TaskSettings taskSettings)
|
|||
case RegionCaptureType.Light:
|
||||
if (!RegionCaptureLightForm.LastSelectionRectangle0Based.IsEmpty)
|
||||
{
|
||||
using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
|
||||
using (Bitmap screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
|
||||
{
|
||||
Image img = ImageHelpers.CropImage(screenshot, RegionCaptureLightForm.LastSelectionRectangle0Based);
|
||||
return new ImageInfo(img);
|
||||
Bitmap bmp = ImageHelpers.CropBitmap(screenshot, RegionCaptureLightForm.LastSelectionRectangle0Based);
|
||||
return new ImageInfo(bmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -65,10 +65,10 @@ protected override ImageInfo Execute(TaskSettings taskSettings)
|
|||
case RegionCaptureType.Transparent:
|
||||
if (!RegionCaptureTransparentForm.LastSelectionRectangle0Based.IsEmpty)
|
||||
{
|
||||
using (Image screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
|
||||
using (Bitmap screenshot = TaskHelpers.GetScreenshot(taskSettings).CaptureFullscreen())
|
||||
{
|
||||
Image img = ImageHelpers.CropImage(screenshot, RegionCaptureTransparentForm.LastSelectionRectangle0Based);
|
||||
return new ImageInfo(img);
|
||||
Bitmap bmp = ImageHelpers.CropBitmap(screenshot, RegionCaptureTransparentForm.LastSelectionRectangle0Based);
|
||||
return new ImageInfo(bmp);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -118,22 +118,22 @@ protected ImageInfo ExecuteRegionCapture(TaskSettings taskSettings)
|
|||
|
||||
protected ImageInfo ExecuteRegionCaptureLight(TaskSettings taskSettings)
|
||||
{
|
||||
Image img = null;
|
||||
Bitmap bmp = null;
|
||||
|
||||
using (RegionCaptureLightForm rectangleLight = new RegionCaptureLightForm(TaskHelpers.GetScreenshot(taskSettings)))
|
||||
{
|
||||
if (rectangleLight.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
img = rectangleLight.GetAreaImage();
|
||||
bmp = rectangleLight.GetAreaImage();
|
||||
|
||||
if (img != null)
|
||||
if (bmp != null)
|
||||
{
|
||||
lastRegionCaptureType = RegionCaptureType.Light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ImageInfo(img);
|
||||
return new ImageInfo(bmp);
|
||||
}
|
||||
|
||||
protected ImageInfo ExecuteRegionCaptureTransparent(TaskSettings taskSettings)
|
||||
|
|
|
@ -218,11 +218,11 @@ private void btnDecodeFromScreen_Click(object sender, EventArgs e)
|
|||
|
||||
TaskSettings taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||
|
||||
using (Image img = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions))
|
||||
using (Bitmap bmp = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions))
|
||||
{
|
||||
if (img != null)
|
||||
if (bmp != null)
|
||||
{
|
||||
DecodeImage((Bitmap)img);
|
||||
DecodeImage(bmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1011,7 +1011,7 @@ public static Bitmap AnnotateImage(Bitmap bmp, string filePath, TaskSettings tas
|
|||
return null;
|
||||
case RegionResult.Region: // Enter
|
||||
case RegionResult.AnnotateRunAfterCaptureTasks:
|
||||
return (Bitmap)form.GetResultImage();
|
||||
return form.GetResultImage();
|
||||
case RegionResult.Fullscreen: // Space or right click
|
||||
case RegionResult.AnnotateContinueTask:
|
||||
return (Bitmap)form.Canvas.Clone();
|
||||
|
@ -1123,9 +1123,9 @@ public static async Task OCRImage(TaskSettings taskSettings = null)
|
|||
{
|
||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||
|
||||
using (Image img = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions))
|
||||
using (Bitmap bmp = RegionCaptureTasks.GetRegionImage(taskSettings.CaptureSettings.SurfaceOptions))
|
||||
{
|
||||
await OCRImage(img, taskSettings);
|
||||
await OCRImage(bmp, taskSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue