Added "Copy" button

This commit is contained in:
Jaex 2024-05-29 03:48:59 +03:00
parent 6ffac8a2cf
commit f5b8239f5e
3 changed files with 40 additions and 8 deletions

View file

@ -23,6 +23,7 @@ private void InitializeComponent()
this.lblResultSize = new System.Windows.Forms.Label();
this.pbStatus = new System.Windows.Forms.PictureBox();
this.btnHelp = new System.Windows.Forms.Button();
this.btnCopy = new System.Windows.Forms.Button();
this.pOutput.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbOutput)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbStatus)).BeginInit();
@ -49,7 +50,7 @@ private void InitializeComponent()
this.pOutput.Location = new System.Drawing.Point(8, 48);
this.pOutput.Name = "pOutput";
this.pOutput.Size = new System.Drawing.Size(968, 605);
this.pOutput.TabIndex = 5;
this.pOutput.TabIndex = 6;
//
// pbOutput
//
@ -65,10 +66,10 @@ private void InitializeComponent()
//
// btnOptions
//
this.btnOptions.Location = new System.Drawing.Point(344, 8);
this.btnOptions.Location = new System.Drawing.Point(512, 8);
this.btnOptions.Name = "btnOptions";
this.btnOptions.Size = new System.Drawing.Size(160, 32);
this.btnOptions.TabIndex = 2;
this.btnOptions.TabIndex = 3;
this.btnOptions.Text = "Options...";
this.btnOptions.UseVisualStyleBackColor = true;
this.btnOptions.Click += new System.EventHandler(this.btnOptions_Click);
@ -90,7 +91,7 @@ private void InitializeComponent()
this.lblResultSize.Location = new System.Drawing.Point(848, 18);
this.lblResultSize.Name = "lblResultSize";
this.lblResultSize.Size = new System.Drawing.Size(108, 24);
this.lblResultSize.TabIndex = 4;
this.lblResultSize.TabIndex = 5;
this.lblResultSize.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// pbStatus
@ -104,19 +105,31 @@ private void InitializeComponent()
//
// btnHelp
//
this.btnHelp.Location = new System.Drawing.Point(512, 8);
this.btnHelp.Location = new System.Drawing.Point(680, 8);
this.btnHelp.Name = "btnHelp";
this.btnHelp.Size = new System.Drawing.Size(32, 32);
this.btnHelp.TabIndex = 3;
this.btnHelp.TabIndex = 4;
this.btnHelp.Text = "?";
this.btnHelp.UseVisualStyleBackColor = true;
this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
//
// btnCopy
//
this.btnCopy.Enabled = false;
this.btnCopy.Location = new System.Drawing.Point(344, 8);
this.btnCopy.Name = "btnCopy";
this.btnCopy.Size = new System.Drawing.Size(160, 32);
this.btnCopy.TabIndex = 2;
this.btnCopy.Text = "Copy";
this.btnCopy.UseVisualStyleBackColor = true;
this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
//
// ScrollingCaptureForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(984, 661);
this.Controls.Add(this.btnCopy);
this.Controls.Add(this.btnHelp);
this.Controls.Add(this.pbStatus);
this.Controls.Add(this.lblResultSize);
@ -150,5 +163,6 @@ private void InitializeComponent()
private System.Windows.Forms.Label lblResultSize;
private System.Windows.Forms.PictureBox pbStatus;
private System.Windows.Forms.Button btnHelp;
private System.Windows.Forms.Button btnCopy;
}
}

View file

@ -116,6 +116,7 @@ private async Task StartCapture()
WindowState = FormWindowState.Minimized;
btnCapture.Enabled = false;
btnUpload.Enabled = false;
btnCopy.Enabled = false;
btnOptions.Enabled = false;
lblResultSize.Text = "";
ResetPictureBox();
@ -162,6 +163,7 @@ private void LoadImage(Bitmap bmp)
if (bmp != null)
{
btnUpload.Enabled = true;
btnCopy.Enabled = true;
pbOutput.Image = bmp;
pOutput.AutoScrollPosition = new Point(0, 0);
lblResultSize.Text = $"{bmp.Width}x{bmp.Height}";
@ -191,6 +193,14 @@ private void UploadResult()
}
}
private void CopyResult()
{
if (manager.Result != null)
{
ClipboardHelpers.CopyImage(manager.Result);
}
}
protected void OnUploadRequested(Bitmap bmp)
{
UploadRequested?.Invoke(bmp);
@ -216,6 +226,11 @@ private void btnUpload_Click(object sender, EventArgs e)
UploadResult();
}
private void btnCopy_Click(object sender, EventArgs e)
{
CopyResult();
}
private void btnOptions_Click(object sender, EventArgs e)
{
using (ScrollingCaptureOptionsForm scrollingCaptureOptionsForm = new ScrollingCaptureOptionsForm(Options))

View file

@ -44,7 +44,7 @@ internal class ScrollingCaptureManager : IDisposable
private Bitmap previousScreenshot;
private bool stopRequested;
private ScrollingCaptureStatus status;
private int bestMatchCount, bestMatchIndex;
private int bestMatchCount, bestMatchIndex, bestIgnoreBottomOffset;
private WindowInfo selectedWindow;
private Rectangle selectedRectangle;
@ -88,6 +88,7 @@ public async Task<ScrollingCaptureStatus> StartCapture()
status = ScrollingCaptureStatus.Failed;
bestMatchCount = 0;
bestMatchIndex = 0;
bestIgnoreBottomOffset = 0;
int ignoreSideOffset = 50;
int ignoreBottomOffset = 50;
Reset();
@ -247,7 +248,7 @@ private Bitmap CombineImages(Bitmap result, Bitmap currentImage, int ignoreSideO
ignoreSideOffset = Math.Max(ignoreSideOffset, currentImage.Width / 20);
ignoreSideOffset = Math.Min(ignoreSideOffset, currentImage.Width / 3);
ignoreBottomOffset = Math.Max(ignoreBottomOffset, currentImage.Height / 20);
ignoreBottomOffset = Math.Max(ignoreBottomOffset, currentImage.Height / 10);
ignoreBottomOffset = Math.Min(ignoreBottomOffset, currentImage.Height / 3);
Rectangle rect = new Rectangle(ignoreSideOffset, result.Height - currentImage.Height,
@ -294,6 +295,7 @@ private Bitmap CombineImages(Bitmap result, Bitmap currentImage, int ignoreSideO
{
matchCount = bestMatchCount;
matchIndex = bestMatchIndex;
ignoreBottomOffset = bestIgnoreBottomOffset;
bestGuess = true;
}
@ -307,6 +309,7 @@ private Bitmap CombineImages(Bitmap result, Bitmap currentImage, int ignoreSideO
{
bestMatchCount = matchCount;
bestMatchIndex = matchIndex;
bestIgnoreBottomOffset = ignoreBottomOffset;
}
Bitmap newResult = new Bitmap(result.Width, result.Height - ignoreBottomOffset + matchHeight);