public static IImage Decode(this IImageCodec imageCodec, string filePath) { if (!imageCodec.IsSupportedFileFormat(filePath)) { throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat); } using (FileStream fs = File.OpenRead(filePath)) return(imageCodec.Decode(fs)); }
public static IImage FromFile(string filePath) { IImageCodec imageCodec = ImageCodec.FromFileExtension(filePath); if (imageCodec is null) { throw new UnsupportedFileFormatException(); } return(imageCodec.Decode(filePath)); }
public IImage FromStream(Stream stream, IFileFormat imageFormat = null) { if (imageFormat is null) { stream = FileFormatFactory.Default.FromStream(stream, out imageFormat); } IImageCodec imageCodec = imageCodecFactory.FromFileFormat(imageFormat); if (imageCodec is null) { throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat); } return(imageCodec.Decode(stream)); }