DocumentAspectRatio Свойство (DocumentPerspectiveCorrectionCommand)
Возвращает или задает соотношение сторон изображения документа.
Property Value
0 - соотношение сторон рассчитывается автоматически.
Значение по умолчанию - 0.
Вот C#/VB.NET код, который демонстрирует, как загрузить изображение с диска, исправить искажение перспективы в изображении документа A4 и сохранить результат в новый файл изображения.
''' <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);
}
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5