Products Downloads Order Support
 

 

 

  Home > Support > Code Tips
 
LEADTOOLS Code Tips

 

 

 

LEADTOOLS Code Tip for: DOCUMENT IMAGE CLEAN-UP

LEAD Document Imaging provides a powerful set of Document Image Clean-up functions. However, most functions only work with image data that is 1 bits per pixel (bpp). If your image is not 1 bpp you can easily change the bit depth using our Color Resolution function. This function allows you to adjust the bit depth of any image to any of the our supported bit depths. We support 1-8,12,16,24,32,48,64 bpp.

Here is some sample code on how to convert a 24 bpp image to a 1bpp image using our version 14 .NET Classes in VB.NET:

Leadtools.Codecs.RasterCodecs.CodecsPath = "D:\Program Files\LEAD Technologies, Inc\Leadtools .NET Class Library\Bin"
Dim RasterCodecs As New Leadtools.Codecs.RasterCodecs
Dim Bitmap As Leadtools.RasterImage
Dim ColorResolution As New Leadtools.ImageProcessing.ColorResolutionCommand
Bitmap = RasterCodecs.Load("D:\Test\Test.jpg")
ColorResolution.BitsPerPixel = 1
ColorResolution.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed
ColorResolution.Run(Bitmap)

After running this code, your image will be converted to 1 bpp. You will now be able to use any of our Document Clean-up functions with this image (Note: When converting to a 1 bpp image, we will automatically convert any color data to black or white).

When converting to bit depths of 8 or less, you have to specify what kind of palette you want to use (you can even use one from disk.) You are also given the option of Dithering the image. When converting to bit depths of 16 or greater you must specify a byte order (instead of a palette). For most images, you should use the Blue-Green-Red byte order.



DICOM Query-Retrieve Demo using C#

The code in the demo below will demonstrate how to create a DICOM query and retrieve application using LEADTOOLS. It shows how to implement the following key concepts:

1. Building a study based query.
2. Implementing date range query.
3. Retrieving a whole series with one command by sending a series level C-Move request.
4. Extracting different DICOM attributes from a C-Find response.
5. Displaying thumbnails for images in a DICOM series.
6. Logging DICOM communication messages.
7. Using LEADTOOLS COM objects in C#
The code in the demo is built with reusability in mind and can be easily tweaked to fit inside any DICOM-enabled application.

Click here to download the demo



Load and display a JPEG image while compressing it in memory.

Below is a code snippet demonstrating how to use LEADTOOLS Mobile Imaging to load a JPEG image and display it while keeping it compressed in memory, to save memory resources on a mobile device.

// Create the LEADTOOLS Viewer Control and add it to your form

RasterImageViewer viewer;
viewer = new RasterImageViewer();
viewer.SizeMode = RasterViewerSizeMode.Fit;
viewer.Bounds = ClientRectangle;
Controls.Add(viewer);
viewer.BringToFront();

// Create the LEADTOOLS Codecs object and use it to load an image

RasterCodecs codecs = new RasterCodecs();
codecs = new RasterCodecs();

// Enable compressed in memory images, in order to save memory

codecs.Options.Load.Compressed = true;
codecs.Options.Load.SuperCompressed = true;

// Load the image file

viewer.Image = codecs.Load(@"\d:\temp\test.jpg", 0, Leadtools.Codecs.CodecsLoadByteOrder.Bgr, 1);

 


Video Conferencing with MPEG-4

LEAD's new MPEG-4 encoder is capable of delivering high quality video in 2 output formats; MP4V (standard) and LMP4, LEAD’s proprietary MPEG-4 video. With LMP4, a super compression option can be used to achieve higher compression. Because of the compression speed, CPU utilization, and wide range of achievable bit rates, this encoder works great with LEAD's video conferencing tools. Through our testing, we have come up with the settings below that allow this encoder to stream high quality video in realistic bandwidth scenarios. This C# code will show you how to create the MPEG-4 encoder programmatically and configure our pre-defined settings.

LMMP4EncoderLib.LMMP4Encoder MPEG4;
MPEG4 = ltmmCapture.GetSubObject(11) as LMMP4EncoderLib.LMMP4Encoder;
MPEG4.OutputFrameRate = 15;
MPEG4.PFrames = 10;
MPEG4.BFrames = 0;
MPEG4.SearchWidth = 8;
MPEG4.SearchHeight = 8;
MPEG4.QFactor = 9;
MPEG4.QuantType = eQuantType.LMP4_QUANTTYPE_Linear;
MPEG4.MotionAlgorithm = eMotionAlgorithm.LMP4_MOTIONALGORITHM_FastSearch;
MPEG4.MotionAccurancy = eMotionAccuracy.LMP4_MOTIONACCURACY_HalfPixel;
MPEG4.MotionVectorPerMacroblock = eMotionVectorPerMacroblock.LMP4_MOTIONVECTOR_OnePerMacroblock;
MPEG4.OutputFormat = eOutputFormat.LMP4_OUTPUTFORMAT_mp4v;
MPEG4.SuperCompression = false;

 


LEADTOOLS ABC
Convert Any File to ABC Format

The link below will take you to a Visual Studio 2005 C# project which allows you to convert any file to ABC format.  You first choose a file, then you can either load a page of the file, convert the entire file to ABC using the selected QFactor, save it as CCITT Group 4, or save the file using each of the QFactors (it saves the entire file using all QFactors).  Scanning functionality is also included.  Each operation (except the scanning) is timed (i.e. loading a page and saving a page).  Enabling the averages forces the application to perform each operation 10 times, then outputs the average time. This application shows which QFactor works best for your types of files

Click here to see the C# project

The ABC compression can reduce the files up to 2/3 the size of a CCITT Group 4 TIFF.  The cleaner the image the better the output size.  Most of the ABC QFactors are lossy compressions so some quality loss will occur.  The tradeoff to the high performance ABC compression and decompression is that it can be slower than CCITT G4.  There are ways to optimize the speed by checking the Load Fast check box and the ABC files will load much faster.  Modified 3 Fast provides the smallest file size but takes some time to compress. Also there can be significant loss in quality.  Our tests have shown LossyFast to be the best all-around option to use for most types of images.  The file sizes are roughly half that of CCITT Group 4 and the compression time is the fastest with little loss in quality of the image. Below is a table of test results that compare each of the QFactors to each other and CCITT Group 4.  The other factor is upload time based on different bandwidths (in this case 56K).  As the data shows, ABC will win out due the smaller file size on small bandwidths.  The larger the bandwidth, however, the less significant ABC becomes.  In this case we went with LossyFast due to the higher quality as the images were going to be OCR'ed once uploaded to the server. 

size (KB)

time to
compress (Sec)

56k

Total (secs)

Quality

Load Time (sec)

 

Uncompressed

24000

0

3428.5

3428.5

High

0

 

CCITT G4

769

0.2

109.8

110.0

High

0

 

Lossless

179

34.4

25.5

59.9

High

6.078

 

Virtual Lossless

175

69.5

25

94.5

High

5.890

 

Remove Border

175

70.5

25

95.5

High

5.781

 

Enhance

175

75.9

25

100.9

High

5.718

 

Modified1

272

27.6

38.8

66.4

High/
Medium

0.093

 

Modified1 Fast

89

9.3

12.7

22.0

low

0.078

 

Modified2

168

33.8

24

57.8

Medium

0.078

 

Modified2 Fast

168

28.3

24

52.3

Low

0.093

 

Modified3

127

25.2

18.1

43.3

Low

0.093

 

Modified3 Fast

127

19.4

18.1

37.5

Low

0.093

 

Lossless Fast

529

4.2

75.5

79.8

High

0.281

 

LossyFast

361

2.843

51.571

54.415

High/
Medium

0.171

Twice as fast as CCITT

 


LEADTOOLS for .NET 2.0 and Visual Studio 2005 Tutorial

Below is a tutorial demonstrating how to dynamically create a LEADTOOLS RasterImageViewer .NET control, add it to a form and load an image. Uses Visual Studio 2005 and the LEADTOOLS for .NET 2.0 Framework. Requires LEADTOOLS v14.5 for .NET 2.0, Visual Studio 2005 and Microsoft .NET Framework 2.0.

  • Start Visual Studio 2005 and create a new Visual Basic Windows Application.
  • Select Project from main menu and then click the Add Reference menu item.
  • In the Add Reference dialog, click the Browse tab page and go to the following folder:
    C:\Program Files\LEAD Technologies, Inc.\LEADTOOLS 14.5\Bin\Dotnet\v20
  • Select the following LEADTOOLS DLL and click OK:
    Leadtools.dll
    Leadtools.Codecs.dll
    Leadtools.WinForms.dll
  • Double click Form1 to add an event to its Load event, the IDE will switch to code view, add the following lines to the Form1_Load method:

Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles MyBase.Load
      ' Add a RasterImageViewer control to the form
      Dim viewer As New Leadtools.WinForms.RasterImageViewer
      viewer.Dock = DockStyle.Fill
      viewer.SizeMode = _
         Leadtools.WinForms.RasterViewerSizeMode.FitIfLarger
      Controls.Add(viewer)
      viewer.BringToFront()

      ' Tell the RasterCodecs object where to find the LEADTOOLS codecs
      Leadtools.Codecs.RasterCodecs.CodecsPath = _
         "C:\Program Files\LEAD Technologies, Inc.\LEADTOOLS 14.5\Bin\Dotnet\v20"

      ' Create a new RasterCodecs object to load files
      Dim codecs As New Leadtools.Codecs.RasterCodecs

      ' Load and view an image into the viewer
      viewer.Image = codecs.Load( _
         "C:\Program Files\LEAD Technologies, Inc.\LEADTOOLS 14.5\Images\Image1.cmp")
   End Sub
End Class

  • Build and run the project by hitting F5 or Ctrl-F5

 


How to Adjust LEADTOOLS' Display for Fax Images

When sending fax images, some fax machines will alter the image so that it is smaller in height than in width. But they also alter the X and Y resolutions of the image to account for this modification. The end result for most fax images is to appear with 8.5 x 11in dimensions. In the below example the fax image on the left has the physical dimensions of 1730 x 1076 pixels. Its X resolution is 204 and its Y resolution is 98. To calculate its logical dimensions you use the formula Pixel Dimension / Resolution = Logical Dimension. For our image: 1730 pixels / 208 pixels per inch = 8.48in and 1076 pixels / 98 pixels per inch = 10.98in.

Now, our control's default behavior is to display the image according to its physical dimensions. As you can see it will appear to be squashed. To correct this, simply set our PaintSizeUseDPI property to True. We then display the image according to its logical dimensions. Now the image will appear as an 8.5 x 11in image.

Keep in mind however that this only changes how the image is displayed. It does not alter the image's physical dimensions, so if you were to save the image as another format or print the image it will still appear squashed. In our next newsletter we will show you how to adjust the image's physical dimensions so that it will always appear as an 8.5 x 11in image.

 


Creating a Video Conference App

The following VB6 code shows the key steps for achieving client-server video, audio and data communication. For a complete code listing, refer to the LEAD NetServer and LEAD NetClient demos in the LEAD v14.5 Multimedia SDK or Video Conferencing SDK.

Server side:

Dim sServer As String
Dim NetMux as LMNetMux

'set the target format:
ltmmCaptureCtrl.TargetFormat = ltmmCapture_TargetFormat_NET

' after selecting video and/or audio devices (both assumed)
' and compressors:
..................

Client side:

' set the player source:
Dim sServer As String

sServer = "ltsf://10.1.1.200"
ltmmPlayCtrl.SourceFile = sServer

' if the AutoStart property is not TRUE, you need to run the player:
ltmmPlay.Run
..................

For the complete code tip click here

 


Using the Cab file in your HTML to Stream Media Files

Below is code using the CAB file supplied with LEADTOOLS Video on Demand SDK to play media streaming from either a standard IIS installation or Windows Media Server. The first step is to add the following code to render the Microsoft MediaPlayer object to your HTML HEAD section:

<SCRIPT language="JavaScript" type="text/javascript">
function w(s){
document.write(s+'\n');
}
function renderActiveX(vid, vidwidth, vidheight){
w('<OBJECT width="'+vidwidth+'" height="'+vidheight+'"');
w('classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"');
w('codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version
=5,1,52,701" type="application/x-oleobject"');
w('standby="Loading Microsoft Windows Media Player components..." id="mediaPlayer">');
w('<PARAM name="fileName" value="'+vid+'">');
w('<PARAM name="animationatStart" value="true">');
w('<PARAM name="transparentatStart" value="true">');
w('<PARAM name="autoStart" value="true">');
w('<PARAM name="showControls" value="false">');
w('<PARAM name="loop" value="true">');
w('</OBJECT>');
.............................

For the complete code tip click here.

 


Simple DVD Image Creation

The demo below will demonstrate how to create a simple DVD Imaging
application using LEADTOOLS. All you need to do is simply provide a
source/destination directory, and it will create a DVD Image for each AVI in
the source directory. It will also resize each video to 720 x 480 in the
process.

Click here to download the sample application

 


Use TWAIN High-level Functions to change transfer options.

This code tip demonstrates the new Twain high-level functions using LEADTOOLS .NET. The code will show you how to easily change the transfer options, without having to know any low level information about the capabilities.

LEADTOOLS .NET high-level functions will deal with the capabilities internally, change their values, and prepare the acquire process in a very easy way.

  // This function will acquire page and save it to file using file transfer mode
      private void AcquireUsingFileMode(TwainSession session)
      {
         try
         {
            // check if file transfer mode is supported or not
            if (session.IsFileTransferAvailable == false)
            {
               // the file transfer mode is not supported
               MessageBox.Show(this, "File transfer mode is not supported!");
               return;
            }

            // get the default transfer options
            session.GetTransferOptions();

            // set transfer mode to file
            session.TransferMode = TwainTransferModes.TwainTransferFile;

            // set transfer file format
            session.TransferFileFormat = (int)TwainCapabilityValue.FileFormatBmp;

            // set transfer file name, the file name will be used to save the acquired page
            session.TransferFileName = @"c:\test.bmp";

            // update transfer options
            session.SetTransferOptions();

            // Acquire the page from source and save it to file
            session.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);

            MessageBox.Show(this, "Acquired page is saved to file", "Acquire to File");
         }
         catch (Exception ex)
         {
            // failure occurred
            MessageBox.Show(this, ex.Message);
         }
      }

 


Create and Modify ICC Profiles in .NET

In the link below we will demonstrate how to create a new ICC profile, and add tags to it. One of these tags will be created from scratch, the other will be taken from an existing ICC profile, modified, and then added to the new ICC profile. The final tag will be taken from another ICC profile and added as-is to the new ICC profile.

For the complete code tip with sample code snippets and screen shots, click here.

 


Drawing on a video frame using LEADTOOLS

This example shows how to use LEAD's Raster COM objects to draw an ellipse from within LEAD's Video Callback Filter's callback function. It uses LEAD's Raster COM objects, LEAD Multimedia COM objects, and LEAD's Video Callback Filter. The project is written in C# with .NET 2003.

In order to process the callback you have to create a .NET class derived from the Video Callback Filter and have the class override the Callback function. In the project below the class is called LEADCallback and it's implementation can be found in the file LEADCallback.cs. All of the code for drawing on the frame is in the callback function.

COM - CallbackFilter Draw Ellipse using COM in Callback.zip

 



LEADTOOLS Web Forms – Create ASP.NET Web Apps.

With the release of LEADTOOLS version 15, LEAD now has released its first version of a .NET Web Form control. Feature support for these new Web Form controls will grow as dictated by feedback from customers. Below are step by step instructions on how to set up a web server to use the controls and run the demos that ship with LEADTOOLS v15. To follow along, you will need either the release or evaluation of LEADTOOLS v15 .NET installed. Click here to download the evaluation.

Click here to download the code tip with screenshots.

Follow these steps to run the LEADTOOLS Web demos developed using Microsoft Visual Studio 2005:

  1. From Windows Start Menu, choose Settings -> Control Panel.
  2. When the Control Panel dialog opens, double-click Administrative Tools to open the Administrative Tools dialog.
  3. Double-click the Internet Information Services node, or right-click My Computer on the desktop and select Manage. When the Computer Management dialog appears, select Services and Applications and when that opens, double-click Internet Information Services.)
  4. Open the Web Sites folder. Right-click the Default Web Site node and select New->Virtual Directory from the context menu. This opens the Virtual Directory Creation Wizard.
  5. Click Next, which opens the Virtual Directory Alias page. In the Alias edit box, enter "CSWebImageViewerDemo" if you are working with the C# demo, or "VBWebImageViewerDemo" if you are working with the Visual Basic demo.
  6. Click Next to open the Web Site Content Directory page.

    Click the Browse button to show the Browse For Folder dialog box, and browse to the location of the LEADTOOLS C# or VB WebImageViewer demo.

    The default path to the C# demo is "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Examples\DotNet\CS\WebImageViewerDemo".

    The default path to the VB demo is "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Examples\DotNet\VB\WebImageViewerDemo".

    Click OK to close the Browse For Folder dialog box.

  7. Click Next to open the Access Permissions page.
  8. Click Next to open the Completion page.
  9. Click Finish to close the wizard and return to the Internet Information Services dialog. Under the Default Web Site node, you will notice the new node you added using the wizard. Right-click on the new node and select Properties.
  10. When the Properties dialog appears, click the Documents tab to open it.

    Click Add to open the Add Default Document dialog box. In the Default Document Name edit box enter "ImageViewerDemo.aspx" and click OK.

    Make sure to move the name up to the top of the Default Document list by clicking the Up arrow until the name is at the top.

  11. Click the Virtual Directory tab to open it and then click Configuration to open the Application Configuration dialog box. You will use this dialog to map the LEADTOOLS ImageGenerator(.leadgen) and ImageInformation(.leadinfo) httphandlers to the ASP.NET engine.
  12. Click the Add button to open the Add/Edit Application Extension Mapping dialog box. Click Browse and browse to the location for the aspnet_isapi.dll file (it can be found at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). Click Open to close the Open dialog. Set the other dialog options as shown in the following figure, and click OK:
  13. Now repeat the previous step to map the LEADTOOLS ".leadinfo" httphandler, using the same dialog options (except changing the Extension to be ".leadinfo" rather than ".leadgen").
  14. Click OK to close the Application Configuration dialog box, and then click OK to close the WebImageViewerDemo Properties dialog box.
  15. Now create another Virtual Directory for the \LEAD Technologies\LEADTOOLS 15\Examples\DotNet\Resources\Web folder which will be used by the demo's webforms for the images and javascript file. To do so, repeat steps (2-7) but on the second page of the wizard type "Resources" in the Alias edit box, and on the third page of the wizard browse to the "\LEAD Technologies\LEADTOOLS 15\Examples\DotNet\Resources\Web" folder.
  16. Now add a reference to the LEADTOOLS assemblies to make the WebImageViewerDemo work correctly. If you are working with the C# tutorial, open the "\LEAD Technologies\LEADTOOLS 15\Examples\DotNet\CS\WebImageViewerDemo" folder and create a new folder named "Bin". Similarily, if you are working with the VB tutorial, open the "\LEAD Technologies\LEADTOOLS 15\Examples\DotNet\VB\WebImageViewerDemo" folder and create a new folder named "Bin".
  17. Copy the following LEADTOOLS assemblies to the demo's bin folder. You can get these assemblies from the "\LEAD Technologies\LEADTOOLS 15\Bin\Dotnet\Win32" folder.
    • Leadtools.Codecs.Bmp.dll
    • Leadtools.Codecs.Cmp.dll
    • Leadtools.Codecs.Cmw.dll
    • Leadtools.Codecs.Fax.dll
    • Leadtools.Codecs.Gif.dll
    • Leadtools.Codecs.dll
    • Leadtools.Codecs.J2k.dll
    • Leadtools.Codecs.Png.dll
    • Leadtools.Codecs.Tif.dll
    • Leadtools.dll
    • Leadtools.Web.dll
  18. Now open an Internet browser and type "http://localhost/CSWebImageViewerDemo" in the Address bar and click Enter or Go to start viewing the WebImageViewerDemo.

Click here to download the code tip with screenshots




Automatically Straighten images using Barcodes

When a user scans a form, often transformations are added to the image such as rotation, zooming, reduction, and translation (shifting in position). These effects make it difficult to identify the different parts of the form, complicating the detection and recognition phases.

Barcodes can be used as registration marks to help identify and locate the different parts of the form. Barcodes have specific locations that can be used to identify the transformations or deformations added to the original form, and then to correct a scanned form’s orientation and resize it to its original size. Below is an example that shows how to detect the rotation angle of an image and correct it.

// This example shows how to detect the rotation angle of an image and correct it by using //barcodes
#include "l_bitmap.h"
#include "ltbar.h"
//Compute the barcode center based on its four corner points
L_VOID ComputeBarcodeCenter(LPPOINT p1, LPPOINT p2, LPPOINT p3, LPPOINT p4,
                            L_INT * pnCx, L_INT *pnCy)
{
   *pnCx = (p1->x + p2->x + p3->x+ p4->x)/4;
   *pnCy = (p1->y + p2->y + p3->y+ p4->y)/4;
}
//Compute the barcode angle
L_VOID ComputeBarcodeAngle(LPPOINT p1, LPPOINT p2, LPPOINT p3, LPPOINT p4,
                           L_INT * pnAngle)
{
   L_DOUBLE dx, dy, dAngle;
   L_DOUBLE pi = 3.1415926535;

   dx = ((p4->x - p1->x) + (p3->x- p2->x))/2;
   dy = ((p4->y - p1->y) + (p3->y- p2->y))/2;

   dAngle = atan2(dy, dx);
   *pnAngle = (L_INT)(dAngle*18000/pi);
}
//Compute Image rotation angle
L_VOID ComputeImageAngleToRef(L_INT nRefCx, L_INT nRefCy, L_INT nRefWidth, L_INT nRefHeight,
                 L_INT nImgCx, L_INT nImgCy, L_INT nImgWidth, L_INT nImgHeight,
                 L_INT nBarAngle, L_INT * pnImgAngle)
{
   L_INT nRefAngle, nImgAngle, nDif;
   L_DOUBLE pi = 3.1415926535;

   if(nBarAngle > 9000)
      nBarAngle -= 18000;

   nRefAngle = (L_INT)(18000*atan2((nRefCy - nRefHeight/2.0),(nRefCx - nRefWidth/2.0))/pi);
   nImgAngle = (L_INT)(18000*atan2((nImgCy - nImgHeight/2.0),(nImgCx - nImgWidth/2.0))/pi);
   nDif = abs(nRefAngle - nImgAngle);
   if(nDif > 18000)
      nDif = 36000-nDif;
   if( nDif > 9000)
      *pnImgAngle = nBarAngle + 18000;
   else
      *pnImgAngle = nBarAngle;
}
// Read the barcode, compute the skew angle and correct the image
L_INT CorrectImageAngle(pBITMAPHANDLE pLeadBitmap)
{
   BARCODE1D bar1D;
   pBARCODEDATA barData;
   L_INT nRet, nStartX, nStartY, nWidth, nHeight, nBarAngle, nImageAngle, nCx, nCy;
   POINT p1, p2, p3, p4;
   //Reference Image Properties
   L_INT nRefCx = 151, nRefCy=99, RefWidth=1908, RefHeight=2471;
   ZeroMemory(&bar1D, sizeof(BARCODE1D));
   bar1D.uStructSize = sizeof(BARCODE1D);
   bar1D.bErrorCheck = TRUE;
   bar1D.nGranularity = 9;
   bar1D.nMinLength = 4;
   bar1D.nDirection = BARCODE_DIR_HORIZONTAL|BARCODE_DIR_VERTICAL;
   //Call the barcode read function to detect the barcode, note that we used
   //BARCODE_RETURN_FOUR_POINTS to get the exact barcode corners
   nRet = L_BarCodeRead(pLeadBitmap, NULL, BARCODE_1D_READ_ANYTYPE,
                 BARCODE_SCANLINES_PER_PIXELS, BARCODE_RETURN_FOUR_POINTS,
                 1, &bar1D, NULL, NULL, &barData,  sizeof(BARCODEDATA));
   if(nRet != SUCCESS)
      return nRet;
   //extract the four corner points
   nStartX = barData[0].rcBarLocation.left;
   nStartY = barData[0].rcBarLocation.top;
   nWidth  = barData[0].rcBarLocation.right - nStartX;
   nHeight = barData[0].rcBarLocation.bottom - nStartY;
   p1.x = (nStartX & 0xffff);
   p1.y = (nStartX >> 16);
   p2.x = (nStartY & 0xffff);
   p2.y = (nStartY >> 16);
   p3.x = (nWidth & 0xffff);
   p3.y = (nWidth >> 16);
   p4.x = (nHeight & 0xffff);
   p4.y = (nHeight >> 16);
   //Find the barcode center
   ComputeBarcodeCenter(&p1, &p2, &p3, &p4, &nCx, &nCy);
   //Find the barcode angle
   ComputeBarcodeAngle(&p1, &p2, &p3, &p4, &nBarAngle);
   //Calculte Image skew angle
   ComputeImageAngleToRef(nRefCx, nRefCy, RefWidth, RefHeight,
                          nCx, nCy, pLeadBitmap->Width, pLeadBitmap->Height,
                          nBarAngle, &nImageAngle);
   //Free barcode data buffer
   L_BarCodeFree(&barData);
   //rotate the image in the oppiste direction of the skew angle to fix it
   return L_RotateBitmap(pLeadBitmap, -nImageAngle, 0, RGB(255,255,255)); 
}

 

Before

After

 

LEADTOOLS Sales: 704-332-5532 | sales@leadtools.com
LEADTOOLS Support: 704-372-9681 |
support@leadtools.com

Products | Downloads | Order | Support | Corporate | News