internal static Size?ImageSize(string file) { var check = SupportedFiles.IsSupportedFile(file); if (!check.HasValue) { return(null); } if (!check.Value) { return(null); } using var magick = new MagickImage(); try { magick.Read(file); } #if DEBUG catch (MagickException e) { Trace.WriteLine("ImageSize returned " + file + " null, \n" + e.Message); return(null); } #else catch (MagickException) { return(null); } #endif return(new Size(magick.Width, magick.Height)); }
/// <summary> /// Check if dragged file is valid, /// returns false for valid file with no thumbnail, /// true for valid file with thumbnail /// and null for invalid file /// </summary> /// <param name="files"></param> /// <returns></returns> private static bool?Drag_Drop_Check(string[] files) { // Return if file strings are null if (files == null) { return(null); } if (files[0] == null) { return(null); } // Return status of useable file return(SupportedFiles.IsSupportedFile(Path.GetExtension(files[0]))); }
internal static BitmapSource GetBitmapSourceThumb(string path) { var supported = SupportedFiles.IsSupportedFile(path); if (!supported.HasValue) { return(null); } if (supported.Value) { return(GetWindowsThumbnail(path)); } else if (!supported.Value) { return(GetMagickImageThumb(path)); } return(null); }
/// <summary> /// Returns thumb for common images /// </summary> /// <param name="x"></param> /// <param name="startup"></param> /// <returns></returns> internal static BitmapSource GetThumb(int x, bool startup) { if (!startup) { return(GetThumb(x)); } var supported = SupportedFiles.IsSupportedFile(Pics[x]); if (!supported.HasValue) { return(null); } if (supported.Value) { return(GetThumb(x)); } return(null); }
/// <summary> /// Decodes image from file to BitMapSource /// </summary> /// <param name="file">Absolute path of the file</param> /// <returns></returns> internal static BitmapSource RenderToBitmapSource(string file) { var check = SupportedFiles.IsSupportedFile(file); if (!check.HasValue) { return(null); } try { using var filestream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, FileOptions.SequentialScan); if (check.Value) { var sKBitmap = SKBitmap.Decode(filestream); if (sKBitmap == null) { return(null); } var pic = sKBitmap.ToWriteableBitmap(); pic.Freeze(); sKBitmap.Dispose(); return(pic); } else { using MagickImage magick = new MagickImage(); var mrs = new MagickReadSettings() { Density = new Density(300, 300), BackgroundColor = MagickColors.Transparent, }; try { magick.Read(filestream, mrs); filestream.Close(); } catch (MagickException e) { #if DEBUG Trace.WriteLine("GetMagickImage returned " + file + " null, \n" + e.Message); #endif return(null); } // Set values for maximum quality magick.Quality = 100; magick.ColorSpace = ColorSpace.Transparent; var pic = magick.ToBitmapSource(); pic.Freeze(); magick.Dispose(); return(pic); } } catch (Exception e) { #if DEBUG Trace.WriteLine("RenderToBitmapSource returned " + file + " null, \n" + e.Message); #endif return(null); } }
/// <summary> /// Decodes image from file to BitMapSource /// </summary> /// <param name="file">Absolute path of the file</param> /// <returns></returns> internal static async Task <BitmapSource> RenderToBitmapSource(string file) { var check = SupportedFiles.IsSupportedFile(file); if (!check.HasValue) { return(null); } try { if (check.Value) { var filestream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, FileOptions.SequentialScan); var sKBitmap = SKBitmap.Decode(filestream); await filestream.DisposeAsync().ConfigureAwait(false); if (sKBitmap == null) { return(null); } var pic = sKBitmap.ToWriteableBitmap(); pic.Freeze(); sKBitmap.Dispose(); return(pic); } else { using MagickImage magick = new MagickImage(); try { magick.Read(file); } catch (MagickException e) { #if DEBUG Trace.WriteLine("GetMagickImage returned " + file + " null, \n" + e.Message); #endif return(null); } // Set values for maximum quality magick.Quality = 100; magick.ColorSpace = ColorSpace.Transparent; var pic = magick.ToBitmapSource(); pic.Freeze(); return(pic); } } catch (Exception e) { #if DEBUG Trace.WriteLine("RenderToBitmapSource returned " + file + " null, \n" + e.Message); #endif return(null); } }