public static Image?Load( IImagingConfig config, Stream stream, VectorType?preferredPixelType = null, DecoderOptions?decoderOptions = null, ImagingProgressCallback <IImageDecoder>?onProgress = null, CancellationToken cancellationToken = default) { using ImageDecoderEnumerator frames = CreateDecoderEnumerator( config, stream, decoderOptions, cancellationToken); frames.Decoder.TargetPixelType = preferredPixelType; if (onProgress != null && frames.Decoder is IProgressReportingCoder <IImageDecoder> progressReporter) { progressReporter.Progress += onProgress; } if (frames.MoveNext()) { return(frames.Current); } return(null); }
public static Image <TPixel>?Load <TPixel>( Stream stream, DecoderOptions?decoderOptions = null, ImagingProgressCallback <IImageDecoder>?onProgress = null, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel <TPixel> { return(Load <TPixel>( ImagingConfig.Default, stream, decoderOptions, onProgress, cancellationToken)); }
public static Image?Load( string filePath, VectorType?preferredPixelType = null, DecoderOptions?decoderOptions = null, ImagingProgressCallback <IImageDecoder>?onProgress = null, CancellationToken cancellationToken = default) { return(Load( ImagingConfig.Default, filePath, preferredPixelType, decoderOptions, onProgress, cancellationToken)); }
public static Image?Load( IImagingConfig config, string filePath, VectorType?preferredPixelType = null, DecoderOptions?decoderOptions = null, ImagingProgressCallback <IImageDecoder>?onProgress = null, CancellationToken cancellationToken = default) { using var fs = File.OpenRead(filePath); return(Load(config, fs, preferredPixelType, decoderOptions, onProgress, cancellationToken)); }
public static Image <TPixel>?Load <TPixel>( IImagingConfig config, string filePath, DecoderOptions?decoderOptions = null, ImagingProgressCallback <IImageDecoder>?onProgress = null, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel <TPixel> { using var fs = File.OpenRead(filePath); return(Load <TPixel>(config, fs, decoderOptions, onProgress, cancellationToken)); }
public static void Save( this IEnumerable <IReadOnlyPixelRows> images, string filePath, ImageFormat?format = null, EncoderOptions?encoderOptions = null, ImagingProgressCallback <IImageEncoder>?onProgress = null, CancellationToken cancellationToken = default) { Save( images, ImagingConfig.Default, filePath, format, encoderOptions, onProgress, cancellationToken); }
public static void Save( this IReadOnlyPixelRows image, Stream output, ImageFormat format, EncoderOptions?encoderOptions = null, ImagingProgressCallback <IImageEncoder>?onProgress = null, CancellationToken cancellationToken = default) { Save( image, ImagingConfig.Default, output, format, encoderOptions, onProgress, cancellationToken); }
public static Image <TPixel>?Load <TPixel>( IImagingConfig config, Stream stream, DecoderOptions?decoderOptions = null, ImagingProgressCallback <IImageDecoder>?onProgress = null, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel <TPixel> { var preferredType = VectorType.Get <TPixel>(); var image = Load( config, stream, preferredType, decoderOptions, onProgress, cancellationToken); return((Image <TPixel>?)image); }
public static void Save( this IEnumerable <IReadOnlyPixelRows> images, IImagingConfig imagingConfig, Stream output, ImageFormat format, EncoderOptions?encoderOptions = null, ImagingProgressCallback <IImageEncoder>?onProgress = null, CancellationToken cancellationToken = default) { if (images == null) { throw new ArgumentNullException(nameof(images)); } if (imagingConfig == null) { throw new ArgumentNullException(nameof(imagingConfig)); } if (format == null) { throw new ArgumentNullException(nameof(format)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } if (!output.CanWrite) { throw new ArgumentException("The stream is not writable.", nameof(output)); } using IImageEncoder encoder = imagingConfig.CreateEncoder(output, format, encoderOptions); if (onProgress != null && encoder is IProgressReportingCoder <IImageEncoder> progressReporter) { progressReporter.Progress += onProgress; } foreach (IReadOnlyPixelRows image in images) { if (!encoder.CanEncodeImage(image)) { break; } encoder.Encode(image, cancellationToken); } }
public static void Save( this IReadOnlyPixelRows image, IImagingConfig imagingConfig, string filePath, ImageFormat?format = null, EncoderOptions?encoderOptions = null, ImagingProgressCallback <IImageEncoder>?onProgress = null, CancellationToken cancellationToken = default) { if (format == null) { format = ImageFormat.GetByPath(filePath)[0]; } Save( new[] { image }, imagingConfig, filePath, format, encoderOptions, onProgress, cancellationToken); }
public static void Save( this IReadOnlyPixelRows image, IImagingConfig imagingConfig, Stream output, ImageFormat format, EncoderOptions?encoderOptions = null, ImagingProgressCallback <IImageEncoder>?onProgress = null, CancellationToken cancellationToken = default) { if (image == null) { throw new ArgumentNullException(nameof(image)); } Save( new[] { image }, imagingConfig, output, format, encoderOptions, onProgress, cancellationToken); }
public static void Save( this IEnumerable <IReadOnlyPixelRows> images, IImagingConfig imagingConfig, string filePath, ImageFormat?format = null, EncoderOptions?encoderOptions = null, ImagingProgressCallback <IImageEncoder>?onProgress = null, CancellationToken cancellationToken = default) { if (format == null) { format = ImageFormat.GetByPath(filePath)[0]; } using var output = OpenWriteStream(filePath); Save( images, imagingConfig, output, format, encoderOptions, onProgress, cancellationToken); }