diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs index 4b48f6a83c..9956127cfb 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Gui.cs @@ -311,7 +311,7 @@ namespace BizHawk.Client.EmuHawk [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")] - public void DrawImage(string path, int x, int y, int? width = null, int? height = null) + public void DrawImage(string path, int x, int y, int? width = null, int? height = null, bool cache = true) { if (!File.Exists(path)) { @@ -329,13 +329,28 @@ namespace BizHawk.Client.EmuHawk else { img = Image.FromFile(path); - _imageCache.Add(path, img); + if (cache) + { + _imageCache.Add(path, img); + } } g.DrawImage(img, x, y, width ?? img.Width, height ?? img.Height); } } + [LuaMethodAttributes( + "clearImageCache", "clears the image cache that is built up by using gui.drawImage, also releases the file handle for cached images")] + public void ClearImageCache() + { + foreach (var image in _imageCache) + { + image.Value.Dispose(); + } + + _imageCache.Clear(); + } + [LuaMethodAttributes( "drawImageRegion", "draws a given region of an image file from the given path at the given coordinate, and optionally with the given size")] public void DrawImageRegion(string path, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int? dest_width = null, int? dest_height = null)