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 : Friday, July 7, 2006 5:55:53 AM(UTC)

phannon  
phannon

Groups: Registered
Posts: 2


Have tried everything to get code below to burn annotation onto single page tif file.  Annotation shows up on screen but doesn't save to tif file.   Any help would be appreciated.

Using VB.net
Using leadtools.net class library


        Dim TcDoc As mydoc.TcDocument
        Dim codecs As New RasterCodecs
        Dim Counter As Int64
        Dim Height As Integer
        Dim Width As Integer
        Dim text As AnnTextObject
        Dim anncodecs As AnnCodecs
        Dim tag As RasterTagMetadata
        Dim tagId As Integer
        Dim i As Int64 = 1
        Dim TifFileName As String


        AddHandler RasterImageViewer1.PostTransformPaint, New PaintEventHandler(AddressOf RasterImageViewer1_PostTransformPaint)
        AddHandler RasterImageViewer1.TransformChanged, New EventHandler(AddressOf RasterImageViewer1_TransformChanged)

        With codecs.Options.Pdf.Load 'Some default settings for appearence purposes
            .DisplayDepth = 16
            .TextAlpha = 4
            .XResolution = 300
            .YResolution = 300
        End With
        Try

            For Each TcDoc In Me.Documents
                For Counter = 1 To TcDoc.PageCount
                    With Me.RasterImageViewer1
                        .Image = codecs.Load(TcDoc.SourceFile, 12, CodecsLoadByteOrder.Gray, Counter, Counter)
                        Application.DoEvents()
                        .SizeMode = WinForms.RasterViewerSizeMode.Normal
                        .SizeMode = WinForms.RasterViewerSizeMode.Fit
                    End With
                    TifFileName = TcDoc.FileNames.Item(Counter - 1)
                    codecs.Save(Me.RasterImageViewer1.Image, TifFileName, RasterImageFormat.TifCcittGroup4, 1)
                    Height = Me.RasterImageViewer1.Image.Height
                    Width = Me.RasterImageViewer1.Image.Width
                    Height -= 75
                    Width -= 400
                    Me.theContainer = New AnnContainer
                    Me.theContainer.Bounds = New AnnRectangle(0, 0, RasterImageViewer1.ImageSize.Width, RasterImageViewer1.ImageSize.Height)
                    Me.theContainer.UnitConverter = New AnnUnitConverter(RasterImageViewer1.ImageDpiX, RasterImageViewer1.ImageDpiY)
                    text = New AnnTextObject
                    text.Text = "Confidential Doc"
                    text.Font = New AnnFont("Arial", New AnnLength(10, AnnUnit.Point), FontStyle.Bold)
                    text.Bounds = New AnnRectangle(Width, Height, 400, 50, AnnUnit.Pixel)
                    text.Bounds = New AnnRectangle(Width, Height, 400, 50, AnnUnit.Pixel)
                    theContainer.Objects.Add(text)
                    Me.RasterImageViewer1.Invalidate(theContainer.InvalidRectangle)
                    anncodecs = New AnnCodecs
                    tag = anncodecs.SaveToTag(Me.theContainer, AnnCodecsTagFormat.Wang) '** Save as Wang compatible
                    tagId = tag.Id
                    codecs.WriteTag(TifFileName, 0, tag)
                    anncodecs.Save(TifFileName, text.Container, AnnCodecsFormat.Serialize, 1, AnnCodecsSavePageMode.Overwrite)
                    codecs.Save(Me.RasterImageViewer1.Image, TifFileName, RasterImageFormat.TifCcittGroup4, 1)                   
                    Me.RasterImageViewer1.Invalidate(theContainer.InvalidRectangle)
                    theContainer.Objects.Clear()
                    tag = Nothing                   
                Next
                i += 1
            Next

        Catch ex As Exception
            MessageBox.Show("Problem adding tags: " & vbCrLf & ex.Message.ToString, "Error: SplitTheFiles", MessageBoxButtons.OK)
            Return False
        End Try
        Return True

 

 

 

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, July 10, 2006 12:30:00 PM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


I do not immediately see any errors in your code and will need to test it.  I am, however, having trouble figuring out what some of your objects are and exactly what you are trying to do here.  Could you reply and attach a more simplified working project that produces your problem?  Once I have this from you I will be able to test your code and try to find a solution.
 
#3 Posted : Tuesday, July 18, 2006 12:53:03 PM(UTC)

phannon  
phannon

Groups: Registered
Posts: 2


Greg, 

Thanks in advance for your help.  The program is loading a pdf file. Trying to burn a annotation to it and save it as a tif file.  See code below. 

Dim pdffile As String = "C:\Documents and Settings\hannonp\Desktop\test.pdf"

Dim TifFileName As String = "C:\Documents and Settings\hannonp\Desktop\test.tif"

Dim codecs As New RasterCodecs

Dim Height As Integer

Dim Width As Integer

Dim text As AnnTextObject

Dim anncodecs As AnnCodecs

Dim tag As RasterTagMetadata

Dim tagId As Integer

 

With codecs.Options.Pdf.Load 'Some default settings for appearence purposes

.DisplayDepth = 16

.TextAlpha = 4

.XResolution = 300

.YResolution = 300

End With

With Me.RasterImageViewer1

.Image = codecs.Load(pdffile, 12, CodecsLoadByteOrder.Gray, 1, 1)

Application.DoEvents()

.SizeMode = WinForms.RasterViewerSizeMode.Normal

.SizeMode = WinForms.RasterViewerSizeMode.Fit

End With

Application.DoEvents()

codecs.Save(Me.RasterImageViewer1.Image, TifFileName, RasterImageFormat.TifCcittGroup4, 1)

Height = Me.RasterImageViewer1.Image.Height

Width = Me.RasterImageViewer1.Image.Width

Height -= 75

Width -= 400

Me.theContainer = New AnnContainer

Me.theContainer.Bounds = New AnnRectangle(0, 0, RasterImageViewer1.ImageSize.Width, RasterImageViewer1.ImageSize.Height)

Me.theContainer.UnitConverter = New AnnUnitConverter(RasterImageViewer1.ImageDpiX, RasterImageViewer1.ImageDpiY)

text = New AnnTextObject

text.Text = "LL00001"

text.Font = New AnnFont("Arial", New AnnLength(10, AnnUnit.Point), FontStyle.Bold)

text.Bounds = New AnnRectangle(Width, Height, 400, 50, AnnUnit.Pixel)

text.Bounds = New AnnRectangle(Width, Height, 400, 50, AnnUnit.Pixel)

theContainer.Objects.Add(text)

Me.RasterImageViewer1.Invalidate(theContainer.InvalidRectangle)

anncodecs = New AnnCodecs

tag = anncodecs.SaveToTag(Me.theContainer, AnnCodecsTagFormat.Wang) '** Save as Wang compatible

tagId = tag.Id

codecs.WriteTag(TifFileName, 0, tag)

anncodecs.Save(TifFileName, text.Container, AnnCodecsFormat.Serialize, 1, AnnCodecsSavePageMode.Overwrite)

codecs.Save(Me.RasterImageViewer1.Image, TifFileName, RasterImageFormat.TifCcittGroup4, 1)

Application.DoEvents()

Me.RasterImageViewer1.Invalidate(theContainer.InvalidRectangle)

Application.DoEvents()

theContainer.Objects.Clear()

tag = Nothing

Application.DoEvents()

'----------------

contact info:

 

 

 

 
#4 Posted : Wednesday, July 19, 2006 6:58:51 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


I believe I understand your problem now.  In order to "burn" the annotations to the TIF file (or any other image) so that it is part of the image, you have to Realize the image.  With non-automated annotations there is not a Realize method, but there is one in the AnnAutomation class.  You can still add annotations programmatically with the AnnAutomation class because it has its own AnnContainer object.  You will need to:

1. Create a new AnnAutomation instance
Dim annAuto1 As AnnAutomation
annAuto1 = New AnnAutomation(New AnnAutomationManager, RasterImageViewer1)

2. Replace any reference to theContainer with annAuto1.Container

3. Call annAuto1.Realize() before codecs.Save
 
#5 Posted : Wednesday, June 20, 2007 1:36:10 PM(UTC)

bsuresh  
bsuresh

Groups: Registered
Posts: 32


Thanks but this method blacks out the objects on the image. I mean, for example, if there is a rubber stamp object and if I want to save it along with image (as part of image), it doesn't retain the stamp picture. It replaces all the pixels with black color. How can we retain the original pixels and realize the object onto the image?

Thanks,
Suresh

(dotnet c# 15)
 
#6 Posted : Thursday, June 21, 2007 4:49:44 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


Most likely this means that your base image is 1bpp.  I would imagine that if you used something lighter like a yellow hilite annotation that the space it took up would become white.

The annotation container and the bitmap are completely separate.  This is why if you load a 1bpp image, your annotations will still be in color while they're in the container.  However if you want them to become part of the bitmap data and retain their color information, you will need to convert your bitmap to 24bpp by either loading it as 24bpp or by using the ColorResolutionCommand.

If you don't want the annotations as part of the image, then just use the AnnCodecs.Save method to create an annotations file.
 
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.189 seconds.