Reference Guide
Programming / Document Cleanup / Deskewing images
In This Topic
    Deskewing images
    In This Topic

    In this tutorial, you will learn how to easily compensate for small rotations to the document that occur in the scanning process.

    Before / After

    1. Let the Auto-Deskew engine handle the process.

      Copy Code
      'We assume that GdPicture has been correctly installed and unlocked.
      Dim oGdPictureImaging As New GdPictureImaging()
      'Loading the image from a file.
      Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif")
      'Checking if the image resource has been loaded correctly.
      If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
          MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Else
          'You can AutoDeskew your image.
          Dim status As GdPictureStatus = oGdPictureImaging.AutoDeskew(imageId)
          If status <> GdPictureStatus.OK Then
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Else
              'After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "AutoDeskewedImage.tif", TiffCompression.TiffCompressionAUTO)
              If status <> GdPictureStatus.OK Then
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
              End If
          End If
          oGdPictureImaging.ReleaseGdPictureImage(imageId)
      End If
      oGdPictureImaging.Dispose()
      Copy Code
      //We assume that GdPicture has been correctly installed and unlocked.
      GdPictureImaging oGdPictureImaging = new GdPictureImaging();
      //Loading the image from a file.
      int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif");
      //Checking if the image resource has been loaded correctly.
      if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
      {
          MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      else
      {
          //You can AutoDeskew your image.
          GdPictureStatus status = oGdPictureImaging.AutoDeskew(imageId);
          if (status != GdPictureStatus.OK)
          {
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          else
          {
              //After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "AutoDeskewedImage.tif", TiffCompression.TiffCompressionAUTO);
              if (status != GdPictureStatus.OK)
              {
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
          }
          oGdPictureImaging.ReleaseGdPictureImage(imageId);
      }
      oGdPictureImaging.Dispose();
    2. Specify the amount of degrees for instigation. Rotated documents with larger angles than the specified value will not be adjusted.

      Copy Code
      'We assume that GdPicture has been correctly installed and unlocked.
      Dim oGdPictureImaging As New GdPictureImaging()
      'Loading the image from a file.
      Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif")
      'Checking if the image resource has been loaded correctly.
      If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
          MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Else
          'You can AutoDeskew your image.
          Dim status As GdPictureStatus = oGdPictureImaging.AutoDeskew(imageId, 10.0)
          If status <> GdPictureStatus.OK Then
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Else
              'After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "AutoDeskewedImage.tif", TiffCompression.TiffCompressionAUTO)
              If status <> GdPictureStatus.OK Then
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
              End If
          End If
          oGdPictureImaging.ReleaseGdPictureImage(imageId)
      End If
      oGdPictureImaging.Dispose()
      Copy Code
      //We assume that GdPicture has been correctly installed and unlocked.
      GdPictureImaging oGdPictureImaging = new GdPictureImaging();
      //Loading the image from a file.
      int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif");
      //Checking if the image resource has been loaded correctly.
      if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
      {
          MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      else
      {
          //You can AutoDeskew your image.
          GdPictureStatus status = oGdPictureImaging.AutoDeskew(imageId, 10.0f);
          if (status != GdPictureStatus.OK)
          {
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          else
          {
              //After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "AutoDeskewedImage.tif", TiffCompression.TiffCompressionAUTO);
              if (status != GdPictureStatus.OK)
              {
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Deskewing images Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
          }
          oGdPictureImaging.ReleaseGdPictureImage(imageId);
      }
      oGdPictureImaging.Dispose();