VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.ImageProcessing.Document Namespace / DocumentPerspectiveCorrectionCommand Class / DocumentAspectRatio Property
Syntax Example Requirements SeeAlso
In This Topic
DocumentAspectRatio Property (DocumentPerspectiveCorrectionCommand)
In This Topic
Gets or sets the document image aspect ratio.
Syntax
'Declaration

<DescriptionAttribute("The document image aspect ratio.")>
<DefaultValueAttribute(0)>
Public Property DocumentAspectRatio As Double

[Description("The document image aspect ratio.")]
[DefaultValue(0)]
public double DocumentAspectRatio { get; set; }

Property Value

0 - aspect ratio is calculated automatically.
Default value is 0.
Example

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);
    }
}

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also