DocumentAspectRatio Property (DocumentPerspectiveCorrectionCommand)
Gets or sets the document image aspect ratio.
Property Value
0 - aspect ratio is calculated automatically.
Default value is 0.
This C#/VB.NET code shows how to load an image from disk, correct the perspective distortion in A4 document image and save the result to a new image file.
''' <summary>
''' Corrects perspective distortion of A4 document image.
''' </summary>
''' <param name="sourceFile">Source file.</param>
''' <param name="resultFile">Result file.</param>
Public Sub ApplyPerspectiveCorrectionA4Paper(sourceFile As String, resultFile As String)
Using image As New Vintasoft.Imaging.VintasoftImage(sourceFile)
' create the perspective correction command
Dim command As New Vintasoft.Imaging.ImageProcessing.Document.DocumentPerspectiveCorrectionCommand()
' set the document aspect ratio to the aspect ratio of the A4 paper
Dim paperSizeA4 As Vintasoft.Imaging.ImageSize = Vintasoft.Imaging.ImageSize.FromPaperKind(Vintasoft.Imaging.PaperSizeKind.A4)
command.DocumentAspectRatio = paperSizeA4.WidthInDip / paperSizeA4.HeightInDip
' apply the perspective correction to a document image
command.ExecuteInPlace(image)
' save the result image to a file
image.Save(resultFile)
End Using
End Sub
/// <summary>
/// Corrects perspective distortion of A4 document image.
/// </summary>
/// <param name="sourceFile">Source file.</param>
/// <param name="resultFile">Result file.</param>
public void ApplyPerspectiveCorrectionA4Paper(string sourceFile, string resultFile)
{
using (Vintasoft.Imaging.VintasoftImage image =
new Vintasoft.Imaging.VintasoftImage(sourceFile))
{
// create the perspective correction command
Vintasoft.Imaging.ImageProcessing.Document.DocumentPerspectiveCorrectionCommand command =
new Vintasoft.Imaging.ImageProcessing.Document.DocumentPerspectiveCorrectionCommand();
// set the document aspect ratio to the aspect ratio of the A4 paper
Vintasoft.Imaging.ImageSize paperSizeA4 = Vintasoft.Imaging.ImageSize.FromPaperKind(Vintasoft.Imaging.PaperSizeKind.A4);
command.DocumentAspectRatio = paperSizeA4.WidthInDip / paperSizeA4.HeightInDip;
// apply the perspective correction to a document image
command.ExecuteInPlace(image);
// save the result image to a file
image.Save(resultFile);
}
}
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5