/// <summary> /// Creates a new image by rotating this image about it's centre. /// </summary> /// <remarks> /// Please note the following: /// <list type="bullet"> /// <item> /// Rotation will bring in either white or black pixels, as specified by <paramref name="fillColor" /> from /// the outside as required. /// </item> /// <item>Above 20 degrees, sampling rotation will be used if shear was requested.</item> /// <item>Colormaps are removed for rotation by area map and shear.</item> /// <item> /// The resulting image can be expanded so that no image pixels are lost. To invoke expansion, /// input the original width and height. For repeated rotation, use of the original width and heigh allows /// expansion to stop at the maximum required size which is a square of side = sqrt(w*w + h*h). /// </item> /// </list> /// <para> /// Please note there is an implicit assumption about RGB component ordering. /// </para> /// </remarks> /// <param name="angle">The angle to rotate by, in radians; clockwise is positive.</param> /// <param name="method">The rotation method to use.</param> /// <param name="fillColor">The fill color to use for pixels that are brought in from the outside.</param> /// <param name="width">The original width; use 0 to avoid embedding</param> /// <param name="height">The original height; use 0 to avoid embedding</param> /// <returns>The image rotated around it's centre.</returns> public Pix Rotate(float angle, RotationMethod method = RotationMethod.AreaMap, RotationFill fillColor = RotationFill.White, int? width = null, int? height = null) { if(width == null) width = this.Width; if(height == null) height = this.Height; if(Math.Abs(angle) < VerySmallAngle) return this.Clone(); IntPtr resultHandle; var rotations = 2 * angle / Math.PI; if(Math.Abs(rotations - Math.Floor(rotations)) < VerySmallAngle) { // handle special case of orthoganal rotations (90, 180, 270) resultHandle = Interop.LeptonicaApi.Native.pixRotateOrth(handle, (int)rotations); } else { // handle general case resultHandle = Interop.LeptonicaApi.Native.pixRotate(handle, angle, method, fillColor, width.Value, height.Value); } if(resultHandle == IntPtr.Zero) throw new LeptonicaException("Failed to rotate image around it's centre."); return new Pix(resultHandle); }
IntPtr pixRotate(IntPtr pixs, float angle, RotationMethod type, RotationFill fillColor, int width, int heigh);
/// <summary> /// Creates a new image by rotating this image about it's centre. /// </summary> /// <remarks> /// Please note the following: /// <list type="bullet"> /// <item> /// Rotation will bring in either white or black pixels, as specified by <paramref name="fillColor" /> from /// the outside as required. /// </item> /// <item>Above 20 degrees, sampling rotation will be used if shear was requested.</item> /// <item>Colormaps are removed for rotation by area map and shear.</item> /// <item> /// The resulting image can be expanded so that no image pixels are lost. To invoke expansion, /// input the original width and height. For repeated rotation, use of the original width and heigh allows /// expansion to stop at the maximum required size which is a square of side = sqrt(w*w + h*h). /// </item> /// </list> /// <para> /// Please note there is an implicit assumption about RGB component ordering. /// </para> /// </remarks> /// <param name="angle">The angle to rotate by, in radians; clockwise is positive.</param> /// <param name="method">The rotation method to use.</param> /// <param name="fillColor">The fill color to use for pixels that are brought in from the outside.</param> /// <param name="width">The original width; use 0 to avoid embedding</param> /// <param name="height">The original height; use 0 to avoid embedding</param> /// <returns>The image rotated around it's centre.</returns> public Pix Rotate(float angle, RotationMethod method = RotationMethod.AreaMap, RotationFill fillColor = RotationFill.White, int?width = null, int?height = null) { if (width == null) { width = this.Width; } if (height == null) { height = this.Height; } if (Math.Abs(angle) < VerySmallAngle) { return(this.Clone()); } IntPtr resultHandle; var rotations = 2 * angle / Math.PI; if (Math.Abs(rotations - Math.Floor(rotations)) < VerySmallAngle) { // handle special case of orthoganal rotations (90, 180, 270) resultHandle = Interop.LeptonicaApi.Native.pixRotateOrth(handle, (int)rotations); } else { // handle general case resultHandle = Interop.LeptonicaApi.Native.pixRotate(handle, angle, method, fillColor, width.Value, height.Value); } if (resultHandle == IntPtr.Zero) { throw new LeptonicaException("Failed to rotate image around it's centre."); } return(new Pix(resultHandle)); }
public static extern IntPtr pixRotate(HandleRef pixs, float angle, RotationMethod type, RotationFill fillColor, int width, int heigh);
/// <summary> /// Creates a new image by rotating this image about it's centre. /// </summary> /// <remarks> /// Please note the following: /// <list type="bullet"> /// <item> /// Rotation will bring in either white or black pixels, as specified by <see cref="fillColor" /> from /// the outside as required. /// </item> /// <item>Above 20 degrees, sampling rotation will be used if shear was requested.</item> /// <item>Colormaps are removed for rotation by area map and shear.</item> /// <item> /// The resulting image can be expanded so that no image pixels are lost. To invoke expansion, /// input the original width and height. For repeated rotation, use of the original width and heigh allows /// expansion to stop at the maximum required size which is a square of side = sqrt(w*w + h*h). /// </item> /// </list> /// <para> /// Please note there is an implicit assumption about RGB component ordering. /// </para> /// </remarks> /// <param name="angle">The angle to rotate by, in radians; clockwise is positive.</param> /// <param name="method">The rotation method to use.</param> /// <param name="fillColor">The fill color to use for pixels that are brought in from the outside.</param> /// <param name="width">The original width; use 0 to avoid embedding</param> /// <param name="height">The original height; use 0 to avoid embedding</param> /// <returns>The image rotated around it's centre.</returns> public Pix Rotate(float angle, RotationMethod method = RotationMethod.AreaMap, RotationFill fillColor = RotationFill.White, int? width = null, int? height = null) { if(width == null) width = this.Width; if(height == null) height = this.Height; var handle = Interop.LeptonicaApi.pixRotate(Handle, angle, method, fillColor, width.Value, height.Value); if(handle == IntPtr.Zero) throw new LeptonicaException("Failed to rotate image around it's centre."); return new Pix(handle); }
internal static extern IntPtr pixRotate(HandleRef pixs, float angle, RotationMethod type, RotationFill fillColor, int width, int heigh);
public static Pix PixRotate(this Pix pix, float angle, float confidence, RotationMethod method = RotationMethod.Shear, RotationFill fill = RotationFill.White) { if (pix == null) { throw new ArgumentNullException("pix is null"); } if (IsRotationConfident(confidence)) { IntPtr pixPtr = LeptonicaNativeApi.Native.pixRotate(pix.Reference, angle.DegreeToRadians(), method, fill, pix.Width, pix.Height); return(Pix.Create(pixPtr)); } return(pix); }
public static Pix Pivot(Pix pix, float angle, RotationMethod method = RotationMethod.AreaMap, RotationFill fillColor = RotationFill.White, int?w = null, int?h = null) { w = w.IsNullOrEmpty() ? pix.Width : w; h = h.IsNullOrEmpty() ? pix.Height : h; if (Math.Abs(angle) < TinyAngle) { return(pix.Clone()); } IntPtr p; double rotations = 2 * angle / Math.PI; if (Math.Abs(rotations - Math.Floor(rotations)) < TinyAngle) { p = LeptonicaNativeApi.Native.pixRotateOrth(pix.Reference, (int)rotations); } else { p = LeptonicaNativeApi.Native.pixRotate(pix.Reference, angle, method, fillColor, w.Value, h.Value); } if (p == IntPtr.Zero) { throw new NullReferenceException("failed to rotate"); } return(Pix.Create(p)); }