Auto detect scroll end option and remove duplicates

This commit is contained in:
Jaex 2015-09-26 12:18:38 +03:00
parent e75b0b03fc
commit fc01a41468
3 changed files with 64 additions and 20 deletions

View file

@ -33,6 +33,8 @@ private void InitializeComponent()
this.lblMaximumScrollCount = new System.Windows.Forms.Label(); this.lblMaximumScrollCount = new System.Windows.Forms.Label();
this.tcScrollingCapture = new System.Windows.Forms.TabControl(); this.tcScrollingCapture = new System.Windows.Forms.TabControl();
this.tpCapture = new System.Windows.Forms.TabPage(); this.tpCapture = new System.Windows.Forms.TabPage();
this.lblScrollMethod = new System.Windows.Forms.Label();
this.cbScrollMethod = new System.Windows.Forms.ComboBox();
this.tpOutput = new System.Windows.Forms.TabPage(); this.tpOutput = new System.Windows.Forms.TabPage();
this.btnResetCombine = new System.Windows.Forms.Button(); this.btnResetCombine = new System.Windows.Forms.Button();
this.btnGuessCombineAdjustments = new System.Windows.Forms.Button(); this.btnGuessCombineAdjustments = new System.Windows.Forms.Button();
@ -55,8 +57,7 @@ private void InitializeComponent()
this.nudTrimRight = new System.Windows.Forms.NumericUpDown(); this.nudTrimRight = new System.Windows.Forms.NumericUpDown();
this.pOutput = new System.Windows.Forms.Panel(); this.pOutput = new System.Windows.Forms.Panel();
this.pbOutput = new System.Windows.Forms.PictureBox(); this.pbOutput = new System.Windows.Forms.PictureBox();
this.cbScrollMethod = new System.Windows.Forms.ComboBox(); this.cbAutoDetectScrollEnd = new System.Windows.Forms.CheckBox();
this.lblScrollMethod = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.nudScrollDelay)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudScrollDelay)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudMaximumScrollCount)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudMaximumScrollCount)).BeginInit();
this.tcScrollingCapture.SuspendLayout(); this.tcScrollingCapture.SuspendLayout();
@ -95,7 +96,7 @@ private void InitializeComponent()
// btnCapture // btnCapture
// //
this.btnCapture.Enabled = false; this.btnCapture.Enabled = false;
this.btnCapture.Location = new System.Drawing.Point(16, 128); this.btnCapture.Location = new System.Drawing.Point(16, 144);
this.btnCapture.Name = "btnCapture"; this.btnCapture.Name = "btnCapture";
this.btnCapture.Size = new System.Drawing.Size(152, 23); this.btnCapture.Size = new System.Drawing.Size(152, 23);
this.btnCapture.TabIndex = 2; this.btnCapture.TabIndex = 2;
@ -161,6 +162,7 @@ private void InitializeComponent()
// //
// tpCapture // tpCapture
// //
this.tpCapture.Controls.Add(this.cbAutoDetectScrollEnd);
this.tpCapture.Controls.Add(this.lblScrollMethod); this.tpCapture.Controls.Add(this.lblScrollMethod);
this.tpCapture.Controls.Add(this.cbScrollMethod); this.tpCapture.Controls.Add(this.cbScrollMethod);
this.tpCapture.Controls.Add(this.btnSelectHandle); this.tpCapture.Controls.Add(this.btnSelectHandle);
@ -178,6 +180,24 @@ private void InitializeComponent()
this.tpCapture.Text = "Capture"; this.tpCapture.Text = "Capture";
this.tpCapture.UseVisualStyleBackColor = true; this.tpCapture.UseVisualStyleBackColor = true;
// //
// lblScrollMethod
//
this.lblScrollMethod.AutoSize = true;
this.lblScrollMethod.Location = new System.Drawing.Point(16, 48);
this.lblScrollMethod.Name = "lblScrollMethod";
this.lblScrollMethod.Size = new System.Drawing.Size(74, 13);
this.lblScrollMethod.TabIndex = 8;
this.lblScrollMethod.Text = "Scroll method:";
//
// cbScrollMethod
//
this.cbScrollMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbScrollMethod.FormattingEnabled = true;
this.cbScrollMethod.Location = new System.Drawing.Point(136, 44);
this.cbScrollMethod.Name = "cbScrollMethod";
this.cbScrollMethod.Size = new System.Drawing.Size(176, 21);
this.cbScrollMethod.TabIndex = 7;
//
// tpOutput // tpOutput
// //
this.tpOutput.Controls.Add(this.btnResetCombine); this.tpOutput.Controls.Add(this.btnResetCombine);
@ -438,23 +458,16 @@ private void InitializeComponent()
this.pbOutput.TabIndex = 0; this.pbOutput.TabIndex = 0;
this.pbOutput.TabStop = false; this.pbOutput.TabStop = false;
// //
// cbScrollMethod // cbAutoDetectScrollEnd
// //
this.cbScrollMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbAutoDetectScrollEnd.AutoSize = true;
this.cbScrollMethod.FormattingEnabled = true; this.cbAutoDetectScrollEnd.Location = new System.Drawing.Point(16, 120);
this.cbScrollMethod.Location = new System.Drawing.Point(136, 44); this.cbAutoDetectScrollEnd.Name = "cbAutoDetectScrollEnd";
this.cbScrollMethod.Name = "cbScrollMethod"; this.cbAutoDetectScrollEnd.Size = new System.Drawing.Size(129, 17);
this.cbScrollMethod.Size = new System.Drawing.Size(176, 21); this.cbAutoDetectScrollEnd.TabIndex = 9;
this.cbScrollMethod.TabIndex = 7; this.cbAutoDetectScrollEnd.Text = "Auto detect scroll end";
// this.cbAutoDetectScrollEnd.UseVisualStyleBackColor = true;
// lblScrollMethod this.cbAutoDetectScrollEnd.CheckedChanged += new System.EventHandler(this.cbAutoDetectScrollEnd_CheckedChanged);
//
this.lblScrollMethod.AutoSize = true;
this.lblScrollMethod.Location = new System.Drawing.Point(16, 48);
this.lblScrollMethod.Name = "lblScrollMethod";
this.lblScrollMethod.Size = new System.Drawing.Size(74, 13);
this.lblScrollMethod.TabIndex = 8;
this.lblScrollMethod.Text = "Scroll method:";
// //
// ScrollingCaptureForm // ScrollingCaptureForm
// //
@ -524,5 +537,6 @@ private void InitializeComponent()
private Button btnResetCombine; private Button btnResetCombine;
private Label lblScrollMethod; private Label lblScrollMethod;
private ComboBox cbScrollMethod; private ComboBox cbScrollMethod;
private CheckBox cbAutoDetectScrollEnd;
} }
} }

View file

@ -58,6 +58,7 @@ public ScrollingCaptureForm(ScrollingCaptureOptions options)
cbScrollMethod.SelectedIndex = (int)Options.ScrollMethod; cbScrollMethod.SelectedIndex = (int)Options.ScrollMethod;
nudScrollDelay.Value = Options.ScrollDelay; nudScrollDelay.Value = Options.ScrollDelay;
nudMaximumScrollCount.Value = Options.MaximumScrollCount; nudMaximumScrollCount.Value = Options.MaximumScrollCount;
cbAutoDetectScrollEnd.Checked = options.AutoDetectScrollEnd;
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
@ -154,6 +155,7 @@ private void StopCapture()
this.ShowActivate(); this.ShowActivate();
tcScrollingCapture.SelectedTab = tpOutput; tcScrollingCapture.SelectedTab = tpOutput;
btnGuessEdges.Enabled = btnGuessCombineAdjustments.Enabled = btnCombine.Enabled = images.Count > 1; btnGuessEdges.Enabled = btnGuessCombineAdjustments.Enabled = btnCombine.Enabled = images.Count > 1;
RemoveLastDuplicates();
ResetCombine(); ResetCombine();
} }
@ -175,6 +177,28 @@ private void Clean()
} }
} }
private void RemoveLastDuplicates()
{
if (images.Count > 1)
{
for (int i = images.Count - 1; i > 0; i--)
{
bool result = ImageHelpers.IsImagesEqual((Bitmap)images[i], (Bitmap)images[i - 1]);
if (result)
{
Image img = images[i];
images.Remove(img);
img.Dispose();
}
else
{
return;
}
}
}
}
private void captureTimer_Tick(object sender, EventArgs e) private void captureTimer_Tick(object sender, EventArgs e)
{ {
Screenshot.CaptureCursor = false; Screenshot.CaptureCursor = false;
@ -187,7 +211,7 @@ private void captureTimer_Tick(object sender, EventArgs e)
currentScrollCount++; currentScrollCount++;
if (currentScrollCount == Options.MaximumScrollCount || IsScrollReachedBottom(selectedWindow.Handle)) if (currentScrollCount == Options.MaximumScrollCount || (Options.AutoDetectScrollEnd && IsScrollReachedBottom(selectedWindow.Handle)))
{ {
StopCapture(); StopCapture();
} }
@ -217,6 +241,11 @@ private void nudMaximumScrollCount_ValueChanged(object sender, EventArgs e)
Options.MaximumScrollCount = (int)nudMaximumScrollCount.Value; Options.MaximumScrollCount = (int)nudMaximumScrollCount.Value;
} }
private void cbAutoDetectScrollEnd_CheckedChanged(object sender, EventArgs e)
{
Options.AutoDetectScrollEnd = cbAutoDetectScrollEnd.Checked;
}
private bool IsScrollReachedBottom(IntPtr handle) private bool IsScrollReachedBottom(IntPtr handle)
{ {
SCROLLINFO scrollInfo = new SCROLLINFO(); SCROLLINFO scrollInfo = new SCROLLINFO();

View file

@ -36,6 +36,7 @@ public class ScrollingCaptureOptions
public ScrollingCaptureScrollMethod ScrollMethod { get; set; } = ScrollingCaptureScrollMethod.SendMessageScroll; public ScrollingCaptureScrollMethod ScrollMethod { get; set; } = ScrollingCaptureScrollMethod.SendMessageScroll;
public int ScrollDelay { get; set; } = 250; public int ScrollDelay { get; set; } = 250;
public int MaximumScrollCount { get; set; } = 20; public int MaximumScrollCount { get; set; } = 20;
public bool AutoDetectScrollEnd { get; set; } = true;
public int TrimLeftEdge { get; set; } = 0; public int TrimLeftEdge { get; set; } = 0;
public int TrimTopEdge { get; set; } = 0; public int TrimTopEdge { get; set; } = 0;
public int TrimRightEdge { get; set; } = 0; public int TrimRightEdge { get; set; } = 0;