Perform high quality rotation on a black and white image.
Syntax
Example
This example will show the difference between normal rotation (IImageProcessingService.Rotate) and high quality rotation (HighQualityRotate)
when performed on a 1 bits/pixel image.
Visual Basic | Copy Code |
---|
Public Sub HighQualityRotateExample()
Dim tifFileName As String = LeadtoolsExamples.Common.ImagesPath.Path & "ocr1.tif"
Dim normalRotateFileName As String = LeadtoolsExamples.Common.ImagesPath.Path & "ocr1_NormalRotated.tif"
Dim highQualityRotateFileName As String = LeadtoolsExamples.Common.ImagesPath.Path & "ocr1_HighQualityRotated.tif"
Dim angle As Integer = 30 * 100
Dim fillColor As String = "White"
Dim sourceBinaryData As RawBinaryData = New RawBinaryData()
sourceBinaryData.Data = File.ReadAllBytes(tifFileName)
Dim convertOptions As RasterConvertOptions = New RasterConvertOptions()
convertOptions.Source = sourceBinaryData
convertOptions.Destination = Nothing
convertOptions.Format = RasterImageFormat.Tif
convertOptions.FirstPage = 1
convertOptions.LastPage = 1
convertOptions.BitsPerPixel = 1
convertOptions.QualityFactor = 2
Dim client As ImageProcessingServiceClient = New ImageProcessingServiceClient()
Dim request As RotateRequest = New RotateRequest()
request.ConvertOptions = convertOptions
request.RegionData = Nothing
request.Angle = angle
request.Flags = RotateCommandFlags.Resize Or RotateCommandFlags.Bicubic
request.FillColor = fillColor
Dim response As CommandResponse = client.Rotate(request)
If Not response.Destination Is Nothing Then
If TypeOf response.Destination Is RawBinaryData Then
File.WriteAllBytes(LeadtoolsExamples.Common.ImagesPath.Path & normalRotateFileName, (TryCast(response.Destination, RawBinaryData)).Data)
End If
End If
client.Close()
Dim documentClient As DocumentProcessingServiceClient = New DocumentProcessingServiceClient()
Dim documentRequest As HighQualityRotateRequest = New HighQualityRotateRequest()
documentRequest.ConvertOptions = convertOptions
documentRequest.RegionData = Nothing
documentRequest.Angle = angle
documentRequest.Flags = HighQualityRotateFlags.Resize Or HighQualityRotateFlags.BestQuality
documentRequest.FillColor = fillColor
response = documentClient.HighQualityRotate(documentRequest)
If Not response.Destination Is Nothing Then
If TypeOf response.Destination Is RawBinaryData Then
File.WriteAllBytes(LeadtoolsExamples.Common.ImagesPath.Path & highQualityRotateFileName, (TryCast(response.Destination, RawBinaryData)).Data)
End If
End If
documentClient.Close()
End Sub |
C# | Copy Code |
---|
public void HighQualityRotateExample() { // Get an image string tifFileName = LeadtoolsExamples.Common.ImagesPath.Path + "ocr1.tif"; string normalRotateFileName = LeadtoolsExamples.Common.ImagesPath.Path + "ocr1_NormalRotated.tif"; string highQualityRotateFileName = LeadtoolsExamples.Common.ImagesPath.Path + "ocr1_HighQualityRotated.tif"; int angle = 30 * 100; string fillColor = "White"; RawBinaryData sourceBinaryData = new RawBinaryData(); sourceBinaryData.Data = File.ReadAllBytes(tifFileName); RasterConvertOptions convertOptions = new RasterConvertOptions(); convertOptions.Source = sourceBinaryData; convertOptions.Destination = null; convertOptions.Format = RasterImageFormat.Tif; convertOptions.FirstPage = 1; convertOptions.LastPage = 1; convertOptions.BitsPerPixel = 1; convertOptions.QualityFactor = 2; // Load the image, rotate normally by 30 degrees and save { ImageProcessingServiceClient client = new ImageProcessingServiceClient(); RotateRequest request = new RotateRequest(); request.ConvertOptions = convertOptions; request.RegionData = null; request.Angle = angle; request.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic; request.FillColor = fillColor; CommandResponse response = client.Rotate(request); if (response.Destination != null) { if (response.Destination is RawBinaryData) File.WriteAllBytes(LeadtoolsExamples.Common.ImagesPath.Path + normalRotateFileName, (response.Destination as RawBinaryData).Data); } client.Close(); } // Load the image, rotate with high quality by 30 degrees and save { DocumentProcessingServiceClient client = new DocumentProcessingServiceClient(); HighQualityRotateRequest request = new HighQualityRotateRequest(); request.ConvertOptions = convertOptions; request.RegionData = null; request.Angle = angle; request.Flags = HighQualityRotateCommandFlags.Resize | HighQualityRotateCommandFlags.BestQuality; request.FillColor = fillColor; CommandResponse response = client.HighQualityRotate(request); if (response.Destination != null) { if (response.Destination is RawBinaryData) File.WriteAllBytes(LeadtoolsExamples.Common.ImagesPath.Path + highQualityRotateFileName, (response.Destination as RawBinaryData).Data); } client.Close(); } // Now compare the saved TIF files and notice the difference in quality between // the normal rotate and high quality } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also