private static Image LoadDDSSquish(string name, ulong hash = 0) { Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback); DdsFile dds = new DdsFile(); // We do not have the texture present so we'll fallback to our empty default texture. if (!File.Exists(name)) { return(RenderStorageSingleton.Instance.TextureThumbnails[0]); } using (var stream = File.Open(name, FileMode.Open)) { try { dds.Load(stream); } catch (Exception ex) { Console.WriteLine(string.Format("Error Message when using DDS Squish: {0}", ex.Message)); return(LoadDDSSquish("Resources/texture.dds").GetThumbnailImage(128, 120, myCallback, IntPtr.Zero)); } } Image Thumbnail = dds.Image().GetThumbnailImage(128, 120, myCallback, IntPtr.Zero); Debug.Assert(Thumbnail != null, string.Format("Thumbnail is wrong here? Trying to load: {0}", name)); if (Thumbnail != null && hash != 0) { RenderStorageSingleton.Instance.TextureThumbnails.TryAdd(hash, Thumbnail); } return(Thumbnail); }
private Image LoadDDSSquish(string name) { Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback); DdsFile dds = new DdsFile(); name = File.Exists(name) == false ? "Resources/texture.dds" : name; using (var stream = File.Open(name, FileMode.Open)) { dds.Load(stream); } var thumbnail = dds.Image().GetThumbnailImage(128, 120, myCallback, IntPtr.Zero); dds = null; return(thumbnail); }
private Image LoadDDSSquish(string name) { Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback); DdsFile dds = new DdsFile(); name = File.Exists(name) == false ? "Resources/texture.dds" : name; var bLoaded = false; using (var stream = File.Open(name, FileMode.Open)) { try { dds.Load(stream); bLoaded = true; } catch (Exception ex) { Utils.Logging.Log.WriteLine("Failed to load DDS: " + name, Utils.Logging.LoggingTypes.WARNING); } } Image thumbnail = null; if (bLoaded) { thumbnail = dds.Image().GetThumbnailImage(128, 120, myCallback, IntPtr.Zero); } else { thumbnail = LoadDDSSquish("Resources/texture.dds"); } dds = null; return(thumbnail); }