public static ImageFileFormat DetermineFileFormat(Stream stream) { if (Bmp.IsBmpStream(stream)) { return(ImageFileFormat.Bmp); } if (Png.IsPngStream(stream)) { return(ImageFileFormat.Png); } if (Jpg.IsJpgStream(stream)) { return(ImageFileFormat.Jpg); } throw new InvalidOperationException("Unsupported image file format."); }
public static Image Load(Stream stream, ImageFileFormat format) { switch (format) { case ImageFileFormat.Bmp: return(Bmp.Load(stream)); case ImageFileFormat.Png: return(Png.Load(stream)); case ImageFileFormat.Jpg: return(Jpg.Load(stream)); default: throw new InvalidOperationException("Unsupported image file format."); } }
public static void Save(Image image, Stream stream, ImageFileFormat format, bool saveAlpha) { switch (format) { case ImageFileFormat.Bmp: Bmp.Save(image, stream, (!saveAlpha) ? Bmp.Format.RGB8 : Bmp.Format.RGBA8); break; case ImageFileFormat.Png: Png.Save(image, stream, (!saveAlpha) ? Png.Format.RGB8 : Png.Format.RGBA8); break; case ImageFileFormat.Jpg: Jpg.Save(image, stream, 95); break; default: throw new InvalidOperationException("Unsupported image file format."); } }