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.
58 lines
2.6 KiB
58 lines
2.6 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>
|
|
/// <typeparam name="T">The pixel format.</typeparam>
|
|
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
|
|
/// <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<T, TP> Rotate<T, TP>(this Image<T, TP> source, float degrees, ProgressEventHandler progressHandler = null)
|
|
where T : IPackedVector<TP>
|
|
where TP : struct
|
|
{
|
|
return Rotate(source, degrees, true, progressHandler);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Rotates an image by the given angle in degrees.
|
|
/// </summary>
|
|
/// <typeparam name="T">The pixel format.</typeparam>
|
|
/// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
|
|
/// <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<T, TP> Rotate<T, TP>(this Image<T, TP> source, float degrees, bool expand, ProgressEventHandler progressHandler = null)
|
|
where T : IPackedVector<TP>
|
|
where TP : struct
|
|
{
|
|
RotateProcessor<T, TP> processor = new RotateProcessor<T, TP> { Angle = degrees, Expand = expand };
|
|
processor.OnProgress += progressHandler;
|
|
|
|
try
|
|
{
|
|
return source.Process(source.Width, source.Height, source.Bounds, source.Bounds, processor);
|
|
}
|
|
finally
|
|
{
|
|
processor.OnProgress -= progressHandler;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|