Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Graphics/src/Graphics/PlatformImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ public IImage Resize(float width, float height, ResizeMode resizeMode = ResizeMo
throw new PlatformNotSupportedException();
}

/// <summary>
/// Saves the contents of this image to the provided <see cref="Stream"/> object.
/// </summary>
/// <param name="stream">The destination stream the bytes of this image will be saved to.</param>
/// <param name="format">The destination format of the image.</param>
/// <param name="quality">The destination quality of the image.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="quality"/> is less than 0 or more than 1.</exception>
/// <exception cref="NotImplementedException">Thrown when the provided value in <paramref name="format"/> does not match with the original format for this image.</exception>
/// <remarks>The <paramref name="quality"/> value is currently unused.</remarks>
public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
if (quality < 0 || quality > 1)
Expand All @@ -59,6 +68,7 @@ public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float qual
}
}

/// <inheritdoc cref="Save"/>
public Task SaveAsync(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
if (quality < 0 || quality > 1)
Expand Down
12 changes: 12 additions & 0 deletions src/Graphics/src/Graphics/Platforms/Android/PlatformImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ public IImage Resize(float width, float height, ResizeMode resizeMode = ResizeMo

public Bitmap PlatformRepresentation => _bitmap;

/// <summary>
/// Saves the contents of this image to the provided <see cref="Stream"/> object.
/// </summary>
/// <param name="stream">The destination stream the bytes of this image will be saved to.</param>
/// <param name="format">The destination format of the image.</param>
/// <param name="quality">The destination quality of the image.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="quality"/> is less than 0 or more than 1.</exception>
/// <remarks>
/// <para>Only <see cref="ImageFormat.Png"/> and <see cref="ImageFormat.Jpeg"/> are supported on this platform.</para>
/// <para>Setting <paramref name="quality"/> is only supported for images with <see cref="ImageFormat.Jpeg"/>.</para>
/// </remarks>
public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
if (quality < 0 || quality > 1)
Expand All @@ -105,6 +116,7 @@ public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float qual
}
}

/// <inheritdoc cref="Save"/>
public async Task SaveAsync(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
if (quality < 0 || quality > 1)
Expand Down
9 changes: 9 additions & 0 deletions src/Graphics/src/Graphics/Platforms/Mac/PlatformImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ public PlatformImage(NSImage image)

public NSImage NativeRepresentation => _image;

/// <summary>
/// Saves the contents of this image to the provided <see cref="Stream"/> object.
/// </summary>
/// <param name="stream">The destination stream the bytes of this image will be saved to.</param>
/// <param name="format">The destination format of the image.</param>
/// <param name="quality">The destination quality of the image.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="quality"/> is less than 0 or more than 1.</exception>
/// <remarks>Setting <paramref name="quality"/> is only supported for images with <see cref="ImageFormat.Jpeg"/>.</remarks>
public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
var data = CreateRepresentation(format, quality);
data.AsStream().CopyTo(stream);
}

/// <inheritdoc cref="Save" />
public async Task SaveAsync(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
var data = CreateRepresentation(format, quality);
Expand Down
12 changes: 12 additions & 0 deletions src/Graphics/src/Graphics/Platforms/Windows/PlatformImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ public IImage Resize(float width, float height, ResizeMode resizeMode = ResizeMo

public float Height => (float)_bitmap.Size.Height;

/// <summary>
/// Saves the contents of this image to the provided <see cref="Stream"/> object.
/// </summary>
/// <param name="stream">The destination stream the bytes of this image will be saved to.</param>
/// <param name="format">The destination format of the image.</param>
/// <param name="quality">The destination quality of the image.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="quality"/> is less than 0 or more than 1.</exception>
/// <remarks>
/// <para>Only <see cref="ImageFormat.Png"/> and <see cref="ImageFormat.Jpeg"/> are supported on this platform.</para>
/// <para>Setting <paramref name="quality"/> is only supported for images with <see cref="ImageFormat.Jpeg"/>.</para>
/// </remarks>
public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
if (quality < 0 || quality > 1)
Expand All @@ -103,6 +114,7 @@ public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float qual
}
}

/// <inheritdoc cref="Save" />
public async Task SaveAsync(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
if (quality < 0 || quality > 1)
Expand Down
13 changes: 13 additions & 0 deletions src/Graphics/src/Graphics/Platforms/iOS/PlatformImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,25 @@ public IImage Resize(float width, float height, ResizeMode resizeMode = ResizeMo

public UIImage PlatformRepresentation => _image;

/// <summary>
/// Saves the contents of this image to the provided <see cref="Stream"/> object.
/// </summary>
/// <param name="stream">The destination stream the bytes of this image will be saved to.</param>
/// <param name="format">The destination format of the image.</param>
/// <param name="quality">The destination quality of the image.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="quality"/> is less than 0 or more than 1.</exception>
/// <exception cref="Exception">Thrown when this image has no data.</exception>
/// <remarks>
/// <para>Only <see cref="ImageFormat.Png"/> and <see cref="ImageFormat.Jpeg"/> are supported on this platform.</para>
/// <para>Setting <paramref name="quality"/> is only supported for images with <see cref="ImageFormat.Jpeg"/>.</para>
/// </remarks>
public void Save(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
var data = CreateData(format, quality);
data.AsStream().CopyTo(stream);
}

/// <inheritdoc cref="Save" />
public async Task SaveAsync(Stream stream, ImageFormat format = ImageFormat.Png, float quality = 1)
{
var data = CreateData(format, quality);
Expand Down