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.
50 lines
2.1 KiB
50 lines
2.1 KiB
// <copyright file="Rotate.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageProcessorCore
|
|
{
|
|
using Processors;
|
|
|
|
/// <summary>
|
|
/// Extension methods for the <see cref="Image"/> type.
|
|
/// </summary>
|
|
public static partial class ImageExtensions
|
|
{
|
|
/// <summary>
|
|
/// Rotates an image by the given angle in degrees, expanding the image to fit the rotated result.
|
|
/// </summary>
|
|
/// <param name="source">The image to rotate.</param>
|
|
/// <param name="degrees">The angle in degrees to perform the rotation.</param>
|
|
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|
/// <returns>The <see cref="Image"/></returns>
|
|
public static Image Rotate(this Image source, float degrees, ProgressEventHandler progressHandler = null)
|
|
{
|
|
return Rotate(source, degrees, true, progressHandler);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rotates an image by the given angle in degrees.
|
|
/// </summary>
|
|
/// <param name="source">The image to rotate.</param>
|
|
/// <param name="degrees">The angle in degrees to perform the rotation.</param>
|
|
/// <param name="expand">Whether to expand the image to fit the rotated result.</param>
|
|
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
|
|
/// <returns>The <see cref="Image"/></returns>
|
|
public static Image Rotate(this Image source, float degrees, bool expand, ProgressEventHandler progressHandler = null)
|
|
{
|
|
RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand };
|
|
processor.OnProgress += progressHandler;
|
|
|
|
try
|
|
{
|
|
return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, processor);
|
|
}
|
|
finally
|
|
{
|
|
processor.OnProgress -= progressHandler;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|