mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-01 04:30:49 +12:00
ScrollingCaptureLightForm improvements
This commit is contained in:
parent
f2e412e46f
commit
43416ecf09
|
@ -923,20 +923,16 @@ public static Bitmap CreateCheckerPattern(int width, int height, Color checkerCo
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsImagesEqual(Bitmap bmp1, Bitmap bmp2)
|
public static bool CompareImages(Bitmap bmp1, Bitmap bmp2)
|
||||||
|
{
|
||||||
|
if (bmp1 != null && bmp2 != null && bmp1.Width == bmp2.Width && bmp1.Height == bmp2.Height)
|
||||||
{
|
{
|
||||||
if ((bmp1 == null) != (bmp2 == null)) return false;
|
|
||||||
if (bmp1.Size != bmp2.Size) return false;
|
|
||||||
|
|
||||||
BitmapData bd1 = bmp1.LockBits(new Rectangle(0, 0, bmp1.Width, bmp1.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
BitmapData bd1 = bmp1.LockBits(new Rectangle(0, 0, bmp1.Width, bmp1.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||||
BitmapData bd2 = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
BitmapData bd2 = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int stride = bd1.Stride;
|
return NativeMethods.memcmp(bd1.Scan0, bd2.Scan0, bd1.Stride * bmp1.Height) == 0;
|
||||||
int count = stride * bmp1.Height;
|
|
||||||
|
|
||||||
return NativeMethods.memcmp(bd1.Scan0, bd2.Scan0, count) == 0;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -945,6 +941,9 @@ public static bool IsImagesEqual(Bitmap bmp1, Bitmap bmp2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsImageTransparent(Bitmap bmp)
|
public static bool IsImageTransparent(Bitmap bmp)
|
||||||
{
|
{
|
||||||
if (bmp.PixelFormat == PixelFormat.Format32bppArgb || bmp.PixelFormat == PixelFormat.Format32bppPArgb)
|
if (bmp.PixelFormat == PixelFormat.Format32bppArgb || bmp.PixelFormat == PixelFormat.Format32bppPArgb)
|
||||||
|
|
|
@ -271,7 +271,7 @@ private void RemoveDuplicates()
|
||||||
{
|
{
|
||||||
for (int i = images.Count - 1; i > 0; i--)
|
for (int i = images.Count - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
bool result = ImageHelpers.IsImagesEqual(images[i], images[i - 1]);
|
bool result = ImageHelpers.CompareImages(images[i], images[i - 1]);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
@ -425,7 +425,7 @@ private bool IsLastTwoImagesSame()
|
||||||
|
|
||||||
if (images.Count > 1)
|
if (images.Count > 1)
|
||||||
{
|
{
|
||||||
result = ImageHelpers.IsImagesEqual(images[images.Count - 1], images[images.Count - 2]);
|
result = ImageHelpers.CompareImages(images[images.Count - 1], images[images.Count - 2]);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,6 +94,8 @@ private void InitializeComponent()
|
||||||
this.Name = "ScrollingCaptureLightForm";
|
this.Name = "ScrollingCaptureLightForm";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "ShareX - Scrolling capture";
|
this.Text = "ShareX - Scrolling capture";
|
||||||
|
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
|
||||||
|
this.Activated += new System.EventHandler(this.ScrollingCaptureLightForm_Activated);
|
||||||
this.Load += new System.EventHandler(this.ScrollingCaptureLightForm_Load);
|
this.Load += new System.EventHandler(this.ScrollingCaptureLightForm_Load);
|
||||||
this.pOutput.ResumeLayout(false);
|
this.pOutput.ResumeLayout(false);
|
||||||
this.pOutput.PerformLayout();
|
this.pOutput.PerformLayout();
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
using ShareX.HelpersLib;
|
using ShareX.HelpersLib;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
@ -109,8 +110,7 @@ private async Task StartCapture()
|
||||||
bestMatchCount = 0;
|
bestMatchCount = 0;
|
||||||
bestMatchIndex = 0;
|
bestMatchIndex = 0;
|
||||||
|
|
||||||
// TODO: Translate
|
btnCapture.Enabled = false;
|
||||||
btnCapture.Text = "Stop";
|
|
||||||
WindowState = FormWindowState.Minimized;
|
WindowState = FormWindowState.Minimized;
|
||||||
Reset();
|
Reset();
|
||||||
selectedWindow.Activate();
|
selectedWindow.Activate();
|
||||||
|
@ -121,19 +121,22 @@ private async Task StartCapture()
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StopCapture()
|
private void StopCapture()
|
||||||
|
{
|
||||||
|
if (isCapturing)
|
||||||
{
|
{
|
||||||
stopRequested = true;
|
stopRequested = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void EndCapture()
|
private void EndCapture()
|
||||||
{
|
{
|
||||||
// TODO: Translate
|
btnCapture.Enabled = true;
|
||||||
btnCapture.Text = "Capture...";
|
|
||||||
btnUpload.Enabled = Result != null;
|
btnUpload.Enabled = Result != null;
|
||||||
pbOutput.Image = Result;
|
pbOutput.Image = Result;
|
||||||
this.ForceActivate();
|
|
||||||
|
|
||||||
isCapturing = false;
|
isCapturing = false;
|
||||||
|
|
||||||
|
this.ForceActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CaptureJob()
|
private async Task CaptureJob()
|
||||||
|
@ -141,9 +144,21 @@ private async Task CaptureJob()
|
||||||
InputHelpers.SendKeyPress(VirtualKeyCode.HOME);
|
InputHelpers.SendKeyPress(VirtualKeyCode.HOME);
|
||||||
NativeMethods.SendMessage(selectedWindow.Handle, (int)WindowsMessages.VSCROLL, (int)ScrollBarCommands.SB_TOP, 0);
|
NativeMethods.SendMessage(selectedWindow.Handle, (int)WindowsMessages.VSCROLL, (int)ScrollBarCommands.SB_TOP, 0);
|
||||||
|
|
||||||
|
Stopwatch timer = new Stopwatch();
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
await Task.Delay(Options.ScrollDelay);
|
int delay = Options.ScrollDelay - (int)timer.ElapsedMilliseconds;
|
||||||
|
|
||||||
|
if (delay > 0)
|
||||||
|
{
|
||||||
|
await Task.Delay(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stopRequested)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Screenshot screenshot = new Screenshot()
|
Screenshot screenshot = new Screenshot()
|
||||||
{
|
{
|
||||||
|
@ -160,6 +175,8 @@ private async Task CaptureJob()
|
||||||
InputHelpers.SendMouseWheel(-120 * 2);
|
InputHelpers.SendMouseWheel(-120 * 2);
|
||||||
currentScrollCount++;
|
currentScrollCount++;
|
||||||
|
|
||||||
|
timer.Restart();
|
||||||
|
|
||||||
if (images.Count > 0)
|
if (images.Count > 0)
|
||||||
{
|
{
|
||||||
Result = await CombineImagesAsync(Result, images[images.Count - 1]);
|
Result = await CombineImagesAsync(Result, images[images.Count - 1]);
|
||||||
|
@ -190,7 +207,7 @@ private bool IsLastTwoImagesSame()
|
||||||
|
|
||||||
if (images.Count > 1)
|
if (images.Count > 1)
|
||||||
{
|
{
|
||||||
result = ImageHelpers.IsImagesEqual(images[images.Count - 1], images[images.Count - 2]);
|
result = ImageHelpers.CompareImages(images[images.Count - 1], images[images.Count - 2]);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
|
@ -232,7 +249,7 @@ private Bitmap CombineImages(Bitmap result, Bitmap currentImage)
|
||||||
|
|
||||||
int matchCount = 0;
|
int matchCount = 0;
|
||||||
int matchIndex = 0;
|
int matchIndex = 0;
|
||||||
int matchLimit = currentImage.Height / 3;
|
int matchLimit = currentImage.Height / 2;
|
||||||
int ignoreSideOffset = Math.Max(50, currentImage.Width / 20);
|
int ignoreSideOffset = Math.Max(50, currentImage.Width / 20);
|
||||||
|
|
||||||
if (currentImage.Width < ignoreSideOffset * 3)
|
if (currentImage.Width < ignoreSideOffset * 3)
|
||||||
|
@ -331,17 +348,15 @@ private async void ScrollingCaptureLightForm_Load(object sender, EventArgs e)
|
||||||
await SelectWindow();
|
await SelectWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void btnCapture_Click(object sender, EventArgs e)
|
private void ScrollingCaptureLightForm_Activated(object sender, EventArgs e)
|
||||||
{
|
|
||||||
if (isCapturing)
|
|
||||||
{
|
{
|
||||||
StopCapture();
|
StopCapture();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
private async void btnCapture_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await SelectWindow();
|
await SelectWindow();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void btnUpload_Click(object sender, EventArgs e)
|
private void btnUpload_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,7 +110,7 @@ public Bitmap CaptureWindowTransparent(IntPtr handle)
|
||||||
|
|
||||||
Bitmap transparentImage;
|
Bitmap transparentImage;
|
||||||
|
|
||||||
if (ImageHelpers.IsImagesEqual(whiteBackground, whiteBackground2))
|
if (ImageHelpers.CompareImages(whiteBackground, whiteBackground2))
|
||||||
{
|
{
|
||||||
transparentImage = CreateTransparentImage(whiteBackground, blackBackground);
|
transparentImage = CreateTransparentImage(whiteBackground, blackBackground);
|
||||||
isTransparent = true;
|
isTransparent = true;
|
||||||
|
|
Loading…
Reference in a new issue