mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.1 KiB
55 lines
2.1 KiB
// <copyright file="ImageExtensions.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageSharp
|
|
{
|
|
using System.IO;
|
|
|
|
using Formats;
|
|
|
|
using ImageSharp.PixelFormats;
|
|
|
|
/// <summary>
|
|
/// Extension methods for the <see cref="Image{TPixel}"/> type.
|
|
/// </summary>
|
|
public static partial class ImageExtensions
|
|
{
|
|
/// <summary>
|
|
/// Saves the image to the given stream with the png format.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
/// <param name="source">The image this method extends.</param>
|
|
/// <param name="stream">The stream to save the image to.</param>
|
|
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|
/// <returns>
|
|
/// The <see cref="Image{TPixel}"/>.
|
|
/// </returns>
|
|
public static Image<TPixel> SaveAsPng<TPixel>(this Image<TPixel> source, Stream stream)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
return SaveAsPng(source, stream, null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Saves the image to the given stream with the png format.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
/// <param name="source">The image this method extends.</param>
|
|
/// <param name="stream">The stream to save the image to.</param>
|
|
/// <param name="options">The options for the encoder.</param>
|
|
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
|
|
/// <returns>
|
|
/// The <see cref="Image{TPixel}"/>.
|
|
/// </returns>
|
|
public static Image<TPixel> SaveAsPng<TPixel>(this Image<TPixel> source, Stream stream, IPngEncoderOptions options)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
PngEncoder encoder = new PngEncoder();
|
|
encoder.Encode(source, stream, options);
|
|
|
|
return source;
|
|
}
|
|
}
|
|
}
|
|
|