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 : Saturday, April 24, 2021 8:22:40 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

All,

I am looking to dynamically add text to each page in a Multi-page TIFF file and to save the text as part of the image.

I found this article, but it appears to assume I will be loading "fixed" content from a predefined file:
https://www.leadtools.co...pport/forum/posts/t6960-

But for my purposes, it needs to be more dynamic.

Basically, the text will be in the format of:

"YYYY-MM-DD HH:MM:SS Page n of t <Unique ID>"

Where:
YYYY-MM-DD - is the date of the image
HH:MM:SS - is the time of the image
"n" is the current page #
"t" is the total # of pages in the multi-page TIFF
<Unique ID> is a 18-character unique Identifier
 

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 : Monday, April 26, 2021 2:45:37 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

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

I've examined the demo you cited and have updated it to the most recent version of the SDK (v21). As part of this, the dependency on the external annotation file was removed as well and it simply creates and places a single text annotation. You can use this as a starting point for your application if you'd prefer.

You can use the AnnTextObject for this purpose and assign the string you want to use to the "Text" property.
https://www.leadtools.co...dh/ac/anntextobject.html
https://www.leadtools.co.../anntextobject-text.html

When constructing your string, you can access the RasterImage.PageCount property to get the total number of pages, and the RasterImage.Page property to get or set the currenty page in the multipage image.
https://www.leadtools.co.../l/rasterimage-page.html

Note file creation and modification timestamps are properties of individaul files and not specific to the SDK itself. Here's some third-party information courtesy of Microsoft on how to read this information.
https://docs.microsoft.c...reationtime?view=net-5.0
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#3 Posted : Monday, April 26, 2021 3:03:18 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Thanks Nick, so it sounds like once I create the Annotation Text object, I can then use the Burn annotations into the page code to save the text to the image.

 
#4 Posted : Monday, April 26, 2021 3:45:41 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

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

Yes--we have a code snippet on our BurnToRectWithDpi() documentation page.
https://www.leadtools.co...e-burntorectwithdpi.html
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#5 Posted : Tuesday, April 27, 2021 2:50:31 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Nick,

When I downloaded and ran the V21 code from: (https://www.leadtools.com/support/forum/posts/t6960-) NET - v21 - Load-Burn Annotations- Without RasImgVwr.zip (94kb)

I get the following error. I tried re-adding the LeadTools references for each assembly, but I get the same error. Any suggestions?

An unhandled exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll

Additional information: Could not load file or assembly 'Leadtools.Codecs, Version=21.0.4.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Bobby
 
#6 Posted : Tuesday, April 27, 2021 3:22:00 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

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

Apologies--I had neglected to include one of the the files in the zip. It's been re-uploaded and should function as expected now. Unzip to its own folder in "C:\LEADTOOLS21\Examples\DotNet\CS" and ensure the x86/Win32 architecture is being used and not AnyCPU.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#7 Posted : Tuesday, April 27, 2021 5:06:19 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Thanks Nick. The Demo works now.

Just one issue, when I change the source image from:

private string srcImageFileName = Application.StartupPath + @"\IMAGE1.CMP";
to a TIFF image, in my case:
private string srcImageFileName = Application.StartupPath + @"\KN7TS0M855SMQCA.tif";

I get an exception. It seems like it is coming from line:
System.Drawing.Graphics gdiPlusGraphics = Leadtools.Drawing.RasterImagePainter.CreateGraphics(srcImage).Graphics;

Any thoughts? Given my goal is to load a TIFF, add text to the top and then burn it to a new image.

Bobby
 
#8 Posted : Tuesday, April 27, 2021 9:24:49 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

The sample application worked, but now I get an error when I try and load a TIFF image instead of the CMP file.

When I change:
private string srcImageFileName = Application.StartupPath + @"\IMAGE1.CMP"
To
private string targetFileName = Application.StartupPath + @"\testAnnBurn.tif"

I get an exception saying "Image is not GDI+ Compatible" on the following line:
System.Drawing.Graphics gdiPlusGraphics = Leadtools.Drawing.RasterImagePainter.CreateGraphics(srcImage).Graphics;

Keep in mind, all I am trying to do is:
1) Load a TIFF image
2) Add a text annotation to the header
3) Burn the annotation to the image
4) Save the TIFF image to disk
 
#9 Posted : Wednesday, April 28, 2021 9:13:49 AM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

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

Note the image has to be GDI+ compatible to be a valid drawing surface for burning annotations. We have more information on GDI+ compatibility in our documentation.
https://www.leadtools.co...erimage-and-gdi-gdi.html

The toolkit also has the RasterImageConverter.MakeCompatible() functionality. I was able to proceed with the burn operation by calling this directly before the RasterImagePainter.CreateGraphics() call.
https://www.leadtools.co...rter-makecompatible.html

You can use RasterImageConverter.TestCompatible() to determine preemptively if this needs to be done.
https://www.leadtools.co...rter-testcompatible.html
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#10 Posted : Thursday, April 29, 2021 10:14:11 AM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Thanks Nick, your suggestions worked. I am able to add a text annotation to each page in the multi-page TIFF.

One more question, I am looking at how to set the font color, but I didn't see any color related properties in the AnnContainer or the AnnTextObject classes.
 
#11 Posted : Thursday, April 29, 2021 11:32:24 AM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

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

The annotation color can be set via the AnnTextObject.TextForeground property.
https://www.leadtools.co...ject-textforeground.html

This property can accept an AnnBrush with a specific color. Standard annotations use the AnnSolidColorBrush for drawing.
https://www.leadtools.co.../annsolidcolorbrush.html

To change the font face and point size, this is accessible via the AnnObject.Font property which AnnTextObject derives from.
https://www.leadtools.co...h/ac/annobject-font.html

Here are the various members of the AnnFont object which can be used to customize the typeface and styling.
https://www.leadtools.co...ac/annfont--members.html
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#12 Posted : Thursday, April 29, 2021 1:16:43 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Thanks again Nick! I believe the only question I have left is I want to hide the border for the annotation. I see the "BorderStyle" property, but that only allows me to chose "Normal", "Cloud" or "Extra Cloud" but I was looking for a "None" or disable border if possible.
 
#13 Posted : Thursday, April 29, 2021 1:57:28 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Nick, disregard the last question. I figured out how to use the AnnStrokes class and apply it to the AnnTextObject instance. (Unless of course you know of a shorter way)

//set bordercolor to white
abBorder = new AnnSolidColorBrush();
abBorder.Color = "White";
AnnStroke annStroke = new AnnStroke();
annStroke.Stroke = abBorder;

text = new AnnTextObject();
text.Stroke = annStroke;
 
#14 Posted : Thursday, April 29, 2021 2:30:03 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

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

The outline for the AnnRectangleObject (which AnnTextObject is derived from) is handled via the Stroke property.
https://www.leadtools.co...ac/annobject-stroke.html

You can set the Stroke to null to not draw the outline.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
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-2024, Yet Another Forum.NET
This page was generated in 0.164 seconds.