Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, October 12, 2017 11:30:15 AM(UTC)
Rob Cline

Groups: Registered
Posts: 41

Thanks: 14 times

I recently updated LeadTools from version 17 to version 19.
The code below was working in v17 without modifying the img dpi.
However, v19 appears to function differently.

I'm adding some text to a 300 dpi tif image using the following simplified code.

100 IntPtr ptrGraph = RasterImagePainter.CreateLeadDC(img);
101 Graphics graph = Graphics.FromHdc(ptrGraph);
102
103 float fontSize = 8.0F * imageDPI / 72.0F;
104 var labelFont = new Font("Courier New", fontSize, FontStyle.Bold);
105 var brush = new SolidBrush(Color.Black);
106
107 graph.DrawString(labelText, labelFont, brush, new Point(labelWidth, (int)(imageDPI * .05) + yAdj));


Before line 100 executes img.XResolution = 300.
After line 100 executes img.XResolution = 150.
After line 101 executes graph.DpiX = 150.

Therefore, a rasterCodecs.Save(img, filename, RasterImageFormat.CcittGroup4, 1); command that follows; ends up saving the tif with dpi = 150 in the header information.
Is this a bug in the new code?
Or could I missing a new parameter or preset that wasn't necessary in v17.
Why would the RasterImagePainter command ever change the original image dpi?
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, October 13, 2017 2:56:56 PM(UTC)

Aaron  
Aaron

Groups: Registered, Tech Support, Administrators
Posts: 71

Was thanked: 4 time(s) in 3 post(s)

Hi,

I tested your sample code in a small sample application and was, unfortunately, not able to reproduce the Resolution change that you are mentioning. Here is the sample code that I used:

Code:

using (var codecs = new RasterCodecs())
{
   codecs.Options.Load.XResolution = 300;
   codecs.Options.Load.YResolution = 300;

   using (RasterImage image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\barcode1.tif"))
   {
      IntPtr ptrGraph = RasterImagePainter.CreateLeadDC(image);
      Graphics graph = Graphics.FromHdc(ptrGraph);

      float fontSize = 8.0F * image.XResolution / 72.0F;
      var labelFont = new Font("Courier New", fontSize, FontStyle.Bold);
      var brush = new SolidBrush(Color.Black);
       
      graph.DrawString("Test", labelFont, brush, new Point(200, (int)(image.XResolution * .05) + 5));

      codecs.Save(image, @"C:\Users\Public\Documents\LEADTOOLS Images\test.tif", RasterImageFormat.Tif, 0);
   }
}


When the RasterImage is originally loaded, it has XResolution and YResolution of 300. After the application runs and the new image is saved, the XResolution and YResolution are still 300. Would there be any additional steps that we would need to take in addition to the code above to reproduce the issue you are seeing?

This could also have been an issue with the DLL versions you are using and may have been resolved with the latest remaster of LEADTOOLS 19 if you do have older DLLs. What file version of the LEADTOOLS 19 Leadtools.Drawing.dll are you currently using? The latest shipping version of Leadtools.Drawing.dll as of now is 19.0.0.29.

If you would like to download the latest LEADTOOLS 19 SDK for testing in case you have older versions of the LEADTOOLS DLLs, you can find the download here:

https://www.leadtools.com/downloads?category=main

If you are still having issues with using the latest version of the LEADTOOLS DLLs, would it be possible for you to provide us with a small sample application that reproduces the issue since we have not been able to reproduce the issue in the sample we provided above so that we are able to debug the issue on our end and help find you a solution?
Aaron Brasington
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#3 Posted : Friday, October 13, 2017 4:12:29 PM(UTC)
Rob Cline

Groups: Registered
Posts: 41

Thanks: 14 times

I'm using version 19.0.4.0 of the Drawing.dll

Below is my actual code with some unimportant code deleted.
The code place a 'page of pages' stamp on either the top or bottom of the page.

Code:
 internal void StampPage(RasterImage pImage, bool pTopOfPage, int pPage, int pPageCount)
        {
            int imageDPI = 300;
            pImage.XResolution = imageDPI;
            pImage.YResolution = imageDPI;

            //int imageDPI = Convert.ToInt32(pImage.Width / 8.5);
            float yAdj = pTopOfPage ? 0 : pImage.Height - imageDPI / 2; // document height - 1/2"
            //float YAdj = (float)(pTopOfPage ? 0 : pImage.Height - pImage.YResolution / 2);

            int labelX = pImage.Width - imageDPI * 5; // Width - 5" => 3.5" in pixels

            try
            {
                // At this point pImage.Xresolution = 300
                IntPtr ptrGraph = RasterImagePainter.CreateLeadDC(pImage);
                // At this point pImage.Xresolution = 150
                Graphics graph = Graphics.FromHdc(ptrGraph);
                //float fRatioCorrection = pImage.XResolution / graph.DpiX;

                pImage.XResolution = imageDPI;
                pImage.YResolution = imageDPI;

                // Therefore, we need to calculate the font size in pixels based on the DPI of the scanned image
                // Explicit set font size to 8pt => 8 * image dpi / 72 pt/in = 33.333 
                float fontSize = 8.0F * imageDPI / 72.0F;
                var labelFont = new Font("Courier New", fontSize, FontStyle.Bold);

                var whiteBrush = new SolidBrush(Color.White);
                var brush = new SolidBrush(Color.Black);
                string labelText = "           Page " + pPage + " of " + pPageCount + " Sequence No. "
                                   + Program.currentDocument.SequenceNo;
                //White Background
                graph.DrawRectangle(new Pen(whiteBrush), labelX      // Page width - 5" => 3.5" in pixels
                                   , 19 + (yAdj * imageDPI)          // 19/300 ~ 1/16" + (either 0" if top of page or total nonsense if bottom of page)
                                   , pImage.Width - labelX           // Page width minus left offset
                                   , (int)(imageDPI * .125 + yAdj)); // 1/8" + (either 0" if top of page or 10.5" if bottom of page)
                graph.FillRectangle(whiteBrush, labelX
                                   , 19 + (yAdj * imageDPI)
                                   , pImage.Width - labelX
                                   , (int)(imageDPI * .125 + yAdj)); // Note 1/8" = 37.5 pixels vs Font size of 33.334 pixels

                graph.DrawString(labelText, labelFont, brush
                                , new Point(labelX + 2  // Two pixel inside of white label
                                           , (int)(imageDPI * .05 + yAdj - 2))); // Two pixel from bottom of white label
                                                                                 //graph.DrawString(strLabel, labelFont, brush
                                                                                 //                , new Point(intLabelX
                                                                                 //                           , (int)(pImage.YResolution * .05 + YAdj)));

                RasterImagePainter.DeleteLeadDC(ptrGraph);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Edited by moderator Thursday, November 2, 2017 9:57:28 AM(UTC)  | Reason: Not specified

 
#4 Posted : Tuesday, October 17, 2017 3:27:13 PM(UTC)
Duncan Quirk

Groups: Registered, Tech Support, Administrators
Posts: 70

Was thanked: 4 time(s) in 4 post(s)

Hello,

Thank you for providing us with your code snippet. I ran through your code, and was unable to reproduce the issue. The DPI of the image after running through your function, and then saving it out is still 300 DPI. As Aaron mentioned in his previous post, the latest shipping version of the Leadtools.Drawing dll is 19.0.0.29. If this is not the version that you are currently working with, I would suggest that you download the latest setup from our website here: https://www.leadtools.com/downloads?category=main

If you are still facing the same issue after using the latest version, would you be able to provide us with a small sample applications that reproduces the issue on your end?
Duncan Quirk
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#5 Posted : Thursday, October 19, 2017 6:41:56 PM(UTC)
Rob Cline

Groups: Registered
Posts: 41

Thanks: 14 times

Thanks for trying.

It appears I was looking at the product version instead of the file version. I am indeed running Leadtools.Drawing dll file version 19.0.0.29 of Product version 19.0.4.0.

I am starting to wonder if the problem is in the twain drivers for our very old Canon workhorse scanners.
But, I still cannot see why the this only happens when I execute line:
IntPtr ptrGraph = RasterImagePainter.CreateLeadDC(pImage);

What's interesting is that it only happens if the RasterImage pImage comes from the scanner which is set at 300 DPI.
If that pImage comes to us via a customer sending us a tif image through a web service the DPI is NOT changed.
 
#6 Posted : Monday, October 23, 2017 2:36:54 PM(UTC)
Duncan Quirk

Groups: Registered, Tech Support, Administrators
Posts: 70

Was thanked: 4 time(s) in 4 post(s)

No problem at all. Is this issue only occurring when you scan in images from that specific scanner? If you have another type of scanner on hand, I would suggest you try with that and see if you are able to reproduce the problem. I would also double check and make sure that you have the latest version of the scanner's driver.
Duncan Quirk
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#7 Posted : Monday, October 23, 2017 3:34:47 PM(UTC)
Rob Cline

Groups: Registered
Posts: 41

Thanks: 14 times

Yes, this only happens when we scan using these batch scanners.
However, they are the only type of batch scanners we have available in our department.

We downloaded the latest version of the drivers (which was still pretty old).
I can immediately scan using the twain drivers from Canon in Acrobat Pro and other scanner enabled software.
And as I sent in a prior question, the Leadtools v19 twain acquire method will not work with these scanners until I acquire an image using the Twack_32 software per individual profile on the PC.
I send a support question about this and responded think it was a machine level issue.
It wasn't until recently we discovered this issue exists at the user profile level of the PC.

If I haven't aquired an image using Twack_32, the application built with Leadtools v19, finds no scanner when I execute the following lines.
twainSession.Startup(Handle, "LEAD Technologies, Inc.", "LEAD Test Applications", "Version 1.0", "TWAIN Test Application", TwainStartupFlags.None);
if (twainSession.SelectSource(string.Empty) != DialogResult.OK)
MessageBox.Show("Error Selecting Source");
 
#8 Posted : Wednesday, October 25, 2017 3:53:59 PM(UTC)
Duncan Quirk

Groups: Registered, Tech Support, Administrators
Posts: 70

Was thanked: 4 time(s) in 4 post(s)

Thank you for providing us with that information. It is difficult to determine the exact cause of the issue, as we are unable to reproduce it in-house, and we do not have the scanner that you mentioned on hand for us to test with. If you would like us to investigate the issue further internally, you can send us the scanner that is causing you issues. Once we are finished investigating the issue, we would send the scanner back.
Duncan Quirk
Developer Support Engineer
LEAD Technologies, Inc.

LEAD Logo
 
#9 Posted : Thursday, October 26, 2017 11:28:28 AM(UTC)
Rob Cline

Groups: Registered
Posts: 41

Thanks: 14 times

That's very gracious of you but all our scanners are either used in production or the one we have for development. Now that I know where the issues occur I have been able to provide work arounds in the code to correct them.

Thank you for your follow up.

Let's call this stream of questions resolved as software incompatibility between the twain drivers and either Leadtools or the new Windows 64 bit operating system.
Either way it is not terminal.
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.094 seconds.