/// <summary> /// Writes the image to the specified file. /// </summary> /// <param name="file">The file to write the image to.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception> public Task WriteAsync(FileInfo file, CancellationToken cancellationToken) { Throw.IfNull(nameof(file), file); var format = EnumHelper.ParseMagickFormatFromExtension(file); var bytes = format != MagickFormat.Unknown ? ToByteArray(format) : ToByteArray(); return(File.WriteAllBytesAsync(file.FullName, bytes, cancellationToken)); }
/// <summary> /// Returns the format information. The extension of the supplied file is used to determine /// the format. /// </summary> /// <param name="file">The file to check.</param> /// <returns>The format information.</returns> public static MagickFormatInfo?Create(FileInfo file) { Throw.IfNull(nameof(file), file); var format = EnumHelper.ParseMagickFormatFromExtension(file); if (format == MagickFormat.Unknown) { return(null); } return(Create(format)); }