Lua - drawImage - speed up by caching images instead of reading them from disk on every call

This commit is contained in:
adelikat 2015-02-07 15:39:16 +00:00
parent ddae5c6d7d
commit 0ee999dde4
1 changed files with 13 additions and 1 deletions

View File

@ -288,6 +288,8 @@ namespace BizHawk.Client.EmuHawk
}
}
private readonly Dictionary<string, Image> ImageCache = new Dictionary<string, Image>();
[LuaMethodAttributes(
"drawImage",
"draws an image file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly"
@ -297,7 +299,17 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.DisplayManager.NeedsToPaint = true;
using (var g = GetGraphics())
{
var img = Image.FromFile(path);
Image img;
if (ImageCache.ContainsKey(path))
{
img = ImageCache[path];
}
else
{
img = Image.FromFile(path);
ImageCache.Add(path, img);
}
g.DrawImage(img, x, y, width ?? img.Width, height ?? img.Height);
}
}