public static void WriteImageTo(this Frame frame, string url, OutputFormat?format = null, string?formatName = null) { using FormatContext fc = FormatContext.AllocOutput(format, formatName, url); using var io = MediaIO.OpenWrite(url); fc.IO = io; WriteImageTo(frame, fc); }
public static byte[] SaveImage(this Frame frame, OutputFormat?format = null, string?formatName = null) { using FormatContext fc = FormatContext.AllocOutput(format, formatName); using var io = MediaIO.OpenDynamic(); fc.IO = io; WriteImageTo(frame, fc); using var dm = io.GetBufferAndClose(); return(dm.AsSpan().ToArray()); }
public static void WriteImageTo(this Frame frame, Stream stream, OutputFormat?format = null, string?formatName = null, bool leaveOpen = false) { using FormatContext fc = FormatContext.AllocOutput(format, formatName); using var io = MediaIO.WriteStream(stream); fc.IO = io; WriteImageTo(frame, fc); if (!leaveOpen) { stream.Close(); } }