Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Fixed memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
tylearymf committed Nov 20, 2020
1 parent ce468e4 commit da7b62c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
6 changes: 3 additions & 3 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[assembly: System.Reflection.AssemblyTitle("SETUNA优化 by tylearymf")]
[assembly: System.Reflection.AssemblyDescription("")]
[assembly: System.Reflection.AssemblyTitle("SETUNA")]
[assembly: System.Reflection.AssemblyDescription("SETUNA优化 by tylearymf")]
[assembly: System.Reflection.AssemblyProduct("SETUNA")]
[assembly: System.Reflection.AssemblyCopyright("Copyright (C) 2008 CLEARUP")]
[assembly: System.Reflection.AssemblyTrademark("")]
[assembly: System.Reflection.AssemblyCompany("clearunit")]
[assembly: System.Runtime.InteropServices.ComVisible(false)]
[assembly: System.Runtime.InteropServices.Guid("4483e561-8b3e-427d-98a4-e0e821b7bf2f")]
[assembly: System.Reflection.AssemblyConfiguration("")]
[assembly: System.Reflection.AssemblyFileVersion("2.5.9")]
[assembly: System.Reflection.AssemblyFileVersion("2.6.0")]
[assembly: System.Runtime.CompilerServices.CompilationRelaxations(8)]
[assembly: System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows = true)]

38 changes: 28 additions & 10 deletions SETUNA/Main/CaptureForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public sealed class CaptureForm : Form
private IContainer components;
private const int GW_HWNDNEXT = 2;
private const int GW_OWNER = 4;
private static Image imgSnap;
private Size ptClipSize;
private Point ptClipStart;
private Point ptEnd;
Expand All @@ -41,6 +40,8 @@ public sealed class CaptureForm : Form
private Thread trd;
private LayerInfo mLayerInfo;

private static Image imgSnap;

private Screen targetScreen
{
get
Expand All @@ -64,7 +65,7 @@ public Size screenNewSize
public CaptureForm(SetunaOption.SetunaOptionData opt)
{
this.InitializeComponent();
imgSnap = new Bitmap(this.screenNewSize.Width, this.screenNewSize.Height, PixelFormat.Format24bppRgb);
ImgSnap = new Bitmap(this.screenNewSize.Width, this.screenNewSize.Height, PixelFormat.Format24bppRgb);
selArea = new Form();
selArea.AutoScaleMode = AutoScaleMode.None;
selArea.BackColor = Color.Blue;
Expand Down Expand Up @@ -176,9 +177,9 @@ private void CaptureForm_MouseUp(object sender, MouseEventArgs e)

private void CaptureForm_Paint(object sender, PaintEventArgs e)
{
if (imgSnap != null)
if (ImgSnap != null)
{
e.Graphics.DrawImageUnscaled(imgSnap, 0, 0);
e.Graphics.DrawImageUnscaled(ImgSnap, 0, 0);
}
}

Expand Down Expand Up @@ -239,7 +240,7 @@ private void CreateClip(Point pt, Size size)
this.bmpClip = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
using (Graphics graphics = Graphics.FromImage(this.bmpClip))
{
graphics.DrawImageUnscaled(imgSnap, -(pt.X - this.targetScreen.Bounds.X), -(pt.Y - this.targetScreen.Bounds.Y));
graphics.DrawImageUnscaled(ImgSnap, -(pt.X - this.targetScreen.Bounds.X), -(pt.Y - this.targetScreen.Bounds.Y));
}
}

Expand Down Expand Up @@ -512,11 +513,11 @@ private void SelectWindowRect(Point ptMouse)

public void ShowCapture(SetunaOption.SetunaOptionData opt)
{
if (imgSnap != null)
if (ImgSnap != null)
{
if ((this.screenNewSize.Width != imgSnap.Width) || (this.screenNewSize.Height != imgSnap.Height))
if ((this.screenNewSize.Width != ImgSnap.Width) || (this.screenNewSize.Height != ImgSnap.Height))
{
imgSnap = new Bitmap(this.screenNewSize.Width, this.screenNewSize.Height, PixelFormat.Format24bppRgb);
ImgSnap = new Bitmap(this.screenNewSize.Width, this.screenNewSize.Height, PixelFormat.Format24bppRgb);
}
this.trd = new Thread(new ThreadStart(this.ThreadTask));
this.trd.IsBackground = true;
Expand Down Expand Up @@ -583,9 +584,9 @@ private void ThreadTask()

var tBitmap = new Bitmap(tScreenSize.Width, tScreenSize.Height, PixelFormat.Format24bppRgb);
tBitmap.SetResolution(tDpi * 96, tDpi * 96);
imgSnap = tBitmap;
ImgSnap = tBitmap;

if (CopyFromScreen(imgSnap, new Point(this.targetScreen.Bounds.X, this.targetScreen.Bounds.Y)))
if (CopyFromScreen(ImgSnap, new Point(this.targetScreen.Bounds.X, this.targetScreen.Bounds.Y)))
{
base.Invoke(new ShowFormDelegate(this.ShowForm));
}
Expand Down Expand Up @@ -630,6 +631,23 @@ public CaptureClosedDelegate OnCaptureClose
}
}

public static Image ImgSnap
{
get
{
return imgSnap;
}
set
{
if (imgSnap != null)
{
imgSnap.Dispose();
}

imgSnap = value;
}
}

public delegate void CaptureClosedDelegate(CaptureForm cform);

private delegate int EnumWindowsCallBack(IntPtr hWnd, int lParam);
Expand Down

0 comments on commit da7b62c

Please sign in to comment.