Dispose of file-loaded bitmap after use

Image.FromFile locks the file until the object is disposed; adjust all uses of Image.FromFile to dispose when finished.

Closes #3857 ty @SNBeast !
This commit is contained in:
Kurt
2023-04-12 23:22:33 -07:00
parent 4caf749064
commit b5262d69b0
2 changed files with 3 additions and 6 deletions

View File

@@ -288,9 +288,7 @@ private void SetFlagsFromFileName(string inpFileName)
if (FileUtil.GetFileSize(inpFileName) > 2058)
return; // 24*20*4(ARGB)=1920
Bitmap bmp; try { bmp = (Bitmap)Image.FromFile(inpFileName); }
catch { return; }
using var bmp = (Bitmap)Image.FromFile(inpFileName);
if (bmp.Width != 24 || bmp.Height != 20)
return;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
@@ -38,8 +38,7 @@ private void B_ImportPNG_Click(object sender, EventArgs e)
if (ofd.ShowDialog() != DialogResult.OK)
return;
Bitmap img = (Bitmap)Image.FromFile(ofd.FileName);
using var img = (Bitmap)Image.FromFile(ofd.FileName);
try
{
bg = CGearImage.GetCGearBackground(img);