internal static Image Transform(Image source, RotationType rotationType, FlippingType flippingType) { Image target; switch (rotationType) { case RotationType.None: { byte[] targetPixels = source.Pixels; byte[] sourcePixels = new byte[targetPixels.Length]; Array.Copy(targetPixels, sourcePixels, targetPixels.Length); target = new Image(source.Width, source.Height, sourcePixels); } break; case RotationType.Rotate90: { target = Rotate90(source); } break; case RotationType.Rotate180: { target = Rotate180(source); } break; case RotationType.Rotate270: { target = Rotate270(source); } break; default: { target = source.Clone(); } break; } switch (flippingType) { case FlippingType.Vertical: FlipX(target); break; case FlippingType.Horizontal: FlipY(target); break; } return(target); }
public void transform_images(RotationType rotate, FlippingType flip) { var image = Image.Load("TestImages/Backdrop.jpg"); var watch = Stopwatch.StartNew(); image = image.Transform(rotate, flip); Trace.WriteLine($"{ rotate }-{ flip }: { watch.ElapsedMilliseconds}ms"); image.VerifyAndSave($"TestResult/Transformed/{ rotate }-{ flip }.jpg"); }
public void transform_images(RotationType rotate, FlippingType flip) { var image = new Image(File.OpenRead("TestImages/Backdrop.jpg")); var watch = Stopwatch.StartNew(); image = image.Transform(rotate, flip); Trace.WriteLine($"{ rotate }-{ flip }: { watch.ElapsedMilliseconds}ms"); image.VerifyAndSave($"TestResult/Transformed/{ rotate }-{ flip }.jpg"); }
internal static Image Transform(Image source, RotationType rotationType, FlippingType flippingType) { Image target; switch (rotationType) { case RotationType.None: { byte[] targetPixels = source.Pixels; byte[] sourcePixels = new byte[targetPixels.Length]; Array.Copy(targetPixels, sourcePixels, targetPixels.Length); target = new Image(source.Width, source.Height, sourcePixels); } break; case RotationType.Rotate90: { target = Rotate90(source); } break; case RotationType.Rotate180: { target = Rotate180(source); } break; case RotationType.Rotate270: { target = Rotate270(source); } break; default: { target = source.Clone(); } break; } switch (flippingType) { case FlippingType.Vertical: FlipX(target); break; case FlippingType.Horizontal: FlipY(target); break; } return target; }
/// <summary> /// Transforms the specified image by flipping and rotating it. First the image /// will be rotated, then the image will be flipped. A new image will be returned. The original image /// will not be changed. /// </summary> /// <param name="source">The image, which should be transformed.</param> /// <param name="target">The new transformed image.</param> /// <param name="rotationType">Type of the rotation.</param> /// <param name="flippingType">Type of the flipping.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="source"/> is null (Nothing in Visual Basic).</para> /// <para>- or -</para> /// <para><paramref name="target"/> is null (Nothing in Visual Basic).</para> /// </exception> internal static void Transform(ImageBase source, ImageBase target, RotationType rotationType, FlippingType flippingType) { Contract.Requires<ArgumentNullException>(source != null, "Source image cannot be null."); Contract.Requires<ArgumentException>(source.IsFilled, "Source image has not been loaded."); Contract.Requires<ArgumentNullException>(target != null, "Target image cannot be null."); switch (rotationType) { case RotationType.None: { byte[] targetPixels = source.Pixels; byte[] sourcePixels = new byte[targetPixels.Length]; Array.Copy(targetPixels, sourcePixels, targetPixels.Length); target.SetPixels(source.PixelWidth, source.PixelHeight, sourcePixels); } break; case RotationType.Rotate90: { Rotate90(source, target); } break; case RotationType.Rotate180: { Rotate180(source, target); } break; case RotationType.Rotate270: { Rotate270(source, target); } break; default: throw new InvalidOperationException(); } switch (flippingType) { case FlippingType.FlipX: FlipX(target); break; case FlippingType.FlipY: FlipY(target); break; } }
/// <summary> /// Transforms the specified image by flipping and rotating it. First the image /// will be rotated, then the image will be flipped. A new image will be returned. The original image /// will not be changed. /// </summary> /// <param name="source">The image, which should be transformed.</param> /// <param name="target">The new transformed image.</param> /// <param name="rotationType">Type of the rotation.</param> /// <param name="flippingType">Type of the flipping.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="source"/> is null (Nothing in Visual Basic).</para> /// <para>- or -</para> /// <para><paramref name="target"/> is null (Nothing in Visual Basic).</para> /// </exception> internal static void Transform(ImageBase source, ImageBase target, RotationType rotationType, FlippingType flippingType) { switch (rotationType) { case RotationType.None: { byte[] targetPixels = source.Pixels; byte[] sourcePixels = new byte[targetPixels.Length]; Array.Copy(targetPixels, sourcePixels, targetPixels.Length); target.SetPixels(source.PixelWidth, source.PixelHeight, sourcePixels); } break; case RotationType.Rotate90: { Rotate90(source, target); } break; case RotationType.Rotate180: { Rotate180(source, target); } break; case RotationType.Rotate270: { Rotate270(source, target); } break; default: throw new InvalidOperationException(); } switch (flippingType) { case FlippingType.Vertical: FlipX(target); break; case FlippingType.Horizontal: FlipY(target); break; } }
/// <summary> /// Transforms the specified image by flipping and rotating it. First the image /// will be rotated, then the image will be flipped. A new image will be returned. The original image /// will not be changed. /// </summary> /// <param name="source">The image, which should be transformed.</param> /// <param name="target">The new transformed image.</param> /// <param name="rotationType">Type of the rotation.</param> /// <param name="flippingType">Type of the flipping.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="source"/> is null (Nothing in Visual Basic).</para> /// <para>- or -</para> /// <para><paramref name="target"/> is null (Nothing in Visual Basic).</para> /// </exception> internal static void Transform(ImageBase source, ImageBase target, RotationType rotationType, FlippingType flippingType) { Contract.Requires <ArgumentNullException>(source != null, "Source image cannot be null."); Contract.Requires <ArgumentException>(source.IsFilled, "Source image has not been loaded."); Contract.Requires <ArgumentNullException>(target != null, "Target image cannot be null."); switch (rotationType) { case RotationType.None: { byte[] targetPixels = source.Pixels; byte[] sourcePixels = new byte[targetPixels.Length]; Array.Copy(targetPixels, sourcePixels, targetPixels.Length); target.SetPixels(source.PixelWidth, source.PixelHeight, sourcePixels); } break; case RotationType.Rotate90: { Rotate90(source, target); } break; case RotationType.Rotate180: { Rotate180(source, target); } break; case RotationType.Rotate270: { Rotate270(source, target); } break; default: throw new InvalidOperationException(); } switch (flippingType) { case FlippingType.FlipX: FlipX(target); break; case FlippingType.FlipY: FlipY(target); break; } }
/// <summary> /// Transforms the specified image by flipping and rotating it. First the image /// will be rotated, then the image will be flipped. A new image will be returned. The original image /// will not be changed. /// </summary> /// <param name="source">The image, which should be transformed.</param> /// <param name="rotationType">Type of the rotation.</param> /// <param name="flippingType">Type of the flipping.</param> /// <returns>The new and transformed image.</returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> is null /// (Nothing in Visual Basic).</exception> public static ExtendedImage Transform(ExtendedImage source, RotationType rotationType, FlippingType flippingType) { Contract.Requires <ArgumentNullException>(source != null, "Source image cannot be null."); Contract.Requires <ArgumentException>(source.IsFilled, "Source image has not been loaded."); return(PerformAction(source, false, (sourceImage, targetImage) => ImageBase.Transform(sourceImage, targetImage, rotationType, flippingType))); }
/// <summary> /// Transforms the specified image by flipping and rotating it. First the image /// will be rotated, then the image will be flipped. A new image will be returned. The original image /// will not be changed. /// </summary> /// <param name="source">The image, which should be transformed.</param> /// <param name="rotationType">Type of the rotation.</param> /// <param name="flippingType">Type of the flipping.</param> /// <returns>The new and transformed image.</returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> is null /// (Nothing in Visual Basic).</exception> public static ExtendedImage Transform(ExtendedImage source, RotationType rotationType, FlippingType flippingType) { Contract.Requires<ArgumentNullException>(source != null, "Source image cannot be null."); Contract.Requires<ArgumentException>(source.IsFilled, "Source image has not been loaded."); return PerformAction(source, false, (sourceImage, targetImage) => ImageBase.Transform(sourceImage, targetImage, rotationType, flippingType)); }
// Transform public static Image Transform(this Image source, RotationType rotate, FlippingType flip) => PerformAction(source, image => ImageBaseOperations.Transform(image, rotate, flip));
// Transform public static Image Transform(this Image source, RotationType rotate, FlippingType flip) => PerformAction(source, false, (sourceImage, targetImage) => ImageBaseOperations.Transform(sourceImage, targetImage, rotate, flip));