Fix Color Picker resource leak (#38122) (#38147)
Some checks are pending
Spell checking / Check Spelling (push) Waiting to run
Spell checking / Report (Push) (push) Blocked by required conditions
Spell checking / Report (PR) (push) Blocked by required conditions
Spell checking / Update PR (push) Waiting to run

* Fix Color Picker resource leak (#38122)

Added a using statement to properly dispose of the Graphics object created from the Bitmap. This fixes resource leak.

* Fix CI complain

* Update MouseInfoProvider.cs

fix whitespace

---------

Co-authored-by: Kai Tao <69313318+vanzue@users.noreply.github.com>
This commit is contained in:
dcog989 2025-04-14 11:20:55 +01:00 committed by GitHub
parent d986592737
commit bec6754aa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -104,8 +104,10 @@ namespace ColorPicker.Mouse
var rect = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1); var rect = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1);
using (var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb)) using (var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb))
{ {
var g = Graphics.FromImage(bmp); using (var g = Graphics.FromImage(bmp)) // Ensure Graphics object is disposed
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy); {
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
}
return bmp.GetPixel(0, 0); return bmp.GetPixel(0, 0);
} }