Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions FocusTreeManager/Helper/ImageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public static class ImageHelper

private const string GFX_ERROR_IMAGE = @"\GFX\Focus\goal_unknown.png";

private static readonly string[] IMAGE_DO_NOT_LOAD = { "shine_mask", "shine_overlay"};
private static readonly string[] IMAGE_DO_NOT_LOAD = { "shine_mask", "shine_overlay" };

public static ImageSource getImageFromGame(string imageName, ImageType source)
{
//If we couldn't find the error image, throw an IO exception
ImageSource errorSource = new BitmapImage(new Uri(Directory.GetCurrentDirectory()
ImageSource errorSource = new BitmapImage(new Uri(Directory.GetCurrentDirectory()
+ GFX_ERROR_IMAGE));
//Try to obtain the image
try
Expand All @@ -66,11 +66,11 @@ public static ImageSource getImageFromGame(string imageName, ImageType source)
switch (source)
{
case ImageType.Goal:
value = AsyncImageLoader.AsyncImageLoader.Worker.
value = AsyncImageLoader.AsyncImageLoader.Worker.
Focuses.LastOrDefault(f => f.Key == imageName).Value;
break;
case ImageType.Event:
value = AsyncImageLoader.AsyncImageLoader.Worker.
value = AsyncImageLoader.AsyncImageLoader.Worker.
Events.LastOrDefault(f => f.Key == imageName).Value;
break;
default:
Expand Down Expand Up @@ -104,7 +104,7 @@ public static Dictionary<string, ImageSource> findAllGameImages(ImageType source
string fullpath = Configurator.getGamePath() + rightFolder;
if (!Directory.Exists(fullpath)) return list;
//For each file in the normal folder
foreach (string filename in Directory.GetFiles(fullpath, "*" + GFX_EXTENTION,
foreach (string filename in Directory.GetFiles(fullpath, "*" + GFX_EXTENTION,
SearchOption.TopDirectoryOnly))
{
if (IMAGE_DO_NOT_LOAD.Any(filename.Contains))
Expand Down Expand Up @@ -190,13 +190,18 @@ public static Dictionary<string, ImageSource> RefreshFromMods(ImageType source)

private static ImageSource ImageSourceForBitmap(Bitmap bmp)
{
if (bmp == null) throw new Exception("bmp is null");
IntPtr handle = bmp.GetHbitmap();
try
{
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(handle,
IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(handle,
IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
finally { DeleteObject(handle); }
finally
{
DeleteObject(handle);
}

}
}
}