LoadAnnotationsFromXMP and Stream
-
- Posts: 14
- Joined: Fri Jan 20, 2012 8:18 am
LoadAnnotationsFromXMP and Stream
Hi,
I need to know how to use the LoadAnnotationsFromXMP and SaveAnnotationsToXMP when saving and loading to a stream.
Kind Regards
Robert
I need to know how to use the LoadAnnotationsFromXMP and SaveAnnotationsToXMP when saving and loading to a stream.
Kind Regards
Robert
Re: LoadAnnotationsFromXMP and Stream
Hi,
Here a snippet. Let me know if you need more information.
Here a snippet. Let me know if you need more information.
Code: Select all
'Part 1: Open image, add annot and save annotation to Stream object
Dim oGdPictureImaging As New GdPictureImaging
Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("c:\001.tif")
Dim oAnnotationManager As New AnnotationManager
Dim annotStream As New IO.MemoryStream()
oAnnotationManager.InitFromGdPictureImage(ImageID)
Dim annot As AnnotationStickyNote = oAnnotationManager.AddStickyNoteAnnot(0, 0, 3, 3, "To Be Investigated")
annot.CanSelect = False
annot.Author = "John"
oAnnotationManager.SaveAnnotationsToXMP(annotStream)
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
'Part 2 open a new image & load the previously saved annotation from the Stream object
ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("c:\002.tif")
oAnnotationManager.InitFromGdPictureImage(ImageID)
oAnnotationManager.LoadAnnotationsFromXMP(annotStream)
oAnnotationManager.SaveAnnotationsToPage()
GdViewer1.DisplayFromGdPictureImage(ImageID) 'Display the image including annotation into a GdViewer object
annotStream.Dispose()
-
- Posts: 14
- Joined: Fri Jan 20, 2012 8:18 am
Re: LoadAnnotationsFromXMP and Stream
Thanks for the code sample. Not much use when it only saves the annotations on the first page. I see from the XML in the file, that it doesn't include the page no of where the annotation needs to go. So I assume I can't use this at all. Can you give me some sample code to read all of the data from all annotations putting it into a class or something so that I can then use that class to put them back?
Re: LoadAnnotationsFromXMP and Stream
Here a suggestion:
- Create X memoryStream (X is your number of page)
- Load the document using an AnnotationManager object (see sample above)
- using the annotationManager object, brows all page and save each page annot content to the good stream.
At this stage you will have all annotation information stored in memory stream, one stream per page. So you have to create your own file structure that you can write/parse. XML is a good option.
IE:
To write & parse the XML file, i suggest you to use the XmlTextReader class. You will find lof of example over the web to use it.
Kind regards,
Loïc
</myAnnotationContainer>
- Create X memoryStream (X is your number of page)
- Load the document using an AnnotationManager object (see sample above)
- using the annotationManager object, brows all page and save each page annot content to the good stream.
At this stage you will have all annotation information stored in memory stream, one stream per page. So you have to create your own file structure that you can write/parse. XML is a good option.
IE:
Code: Select all
<GdPictureAnnotationsContainer>
<PageAnnots>
<PageNo>1</PageNo>
<Content> [CONTENT OF THE FIRST STREAM HERE] </Content>
</PageAnnots>
<PageAnnots>
<PageNo>2</PageNo>
<Content> [CONTENT OF THE SECONDSTREAM HERE] </Content>
</PageAnnots>
</GdPictureAnnotationsContainer>
To write & parse the XML file, i suggest you to use the XmlTextReader class. You will find lof of example over the web to use it.
Kind regards,
Loïc
</myAnnotationContainer>
-
- Posts: 14
- Joined: Fri Jan 20, 2012 8:18 am
Re: LoadAnnotationsFromXMP and Stream
Hi,
OK. I see what I need to do. THe problem is, I can't see any sample code to go through each of the annotations that are already on the image. I can see how to get the annotation one by one, but there is not enough information on that annotation to do something with. So how do I go through each Annotation and get the information?
OK. I see what I need to do. THe problem is, I can't see any sample code to go through each of the annotations that are already on the image. I can see how to get the annotation one by one, but there is not enough information on that annotation to do something with. So how do I go through each Annotation and get the information?
Re: LoadAnnotationsFromXMP and Stream
Hi,
I'm evaluating GDPicture and I am having the same problem. Since I'm not yet fully acquainted with the software, I would really appreciate some sample code how to do this. Thanks for your help.
Marc
I'm evaluating GDPicture and I am having the same problem. Since I'm not yet fully acquainted with the software, I would really appreciate some sample code how to do this. Thanks for your help.
Marc
-
- Posts: 14
- Joined: Fri Jan 20, 2012 8:18 am
Re: LoadAnnotationsFromXMP and Stream
Here is something that I am using to build up the properties of the Annoations on each page. This puts all of the properties in a string which I will then use later on. This might not be the best way to do this, but it works.
Loic, is there an easier way to do this?
Loic, is there an easier way to do this?
Code: Select all
Dim annMan As New AnnotationManager
Dim i, x, PageNo As Integer
Dim info() As System.Reflection.PropertyInfo
Dim Anno1 As Object
Dim AllAnnos As String = ""
Dim Type As String
For PageNo = 1 To imageViewer.PageCount
imageViewer.DisplayPage(PageNo)
For i = 0 To imageViewer.GetAnnotationCount - 1
Dim NewAnnot As GdPicture.Annotation
NewAnnot = imageViewer.GetAnnotationFromIdx(i)
Select Case NewAnnot.GetAnnotationType
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeConnectedLines
Dim Anno As GdPicture.AnnotationConnectedLines
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationConnectedLines)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationConnectedLines"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeEllipse
Dim Anno As GdPicture.AnnotationEllipse
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationEllipse)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationEllipse"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeEmbeddedImage
Dim Anno As GdPicture.AnnotationEmbeddedImage
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationEmbeddedImage)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationEmbeddedImage"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeFreeHand
Dim Anno As GdPicture.AnnotationFreeHand
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationFreeHand)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationFreeHand"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeFreeHandHighlighter
Dim Anno As GdPicture.AnnotationFreeHandHighlighter
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationFreeHandHighlighter)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationFreeHandHighlighter"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeFreeHandPolygon
Dim Anno As GdPicture.AnnotationFreehandPolygon
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationFreehandPolygon)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationFreehandPolygon"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeLine
Dim Anno As GdPicture.AnnotationLine
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationLine)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationLine"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeLineArrow
Dim Anno As GdPicture.AnnotationLineArrow
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationLineArrow)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationLineArrow"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeLink
Dim Anno As GdPicture.AnnotationLink
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationLink)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationLink"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypePolygon
Dim Anno As GdPicture.AnnotationPolygon
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationPolygon)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationPolygon"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeRectangle
Dim Anno As GdPicture.AnnotationRectangle
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationRectangle)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationRectangle"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeRectangleHighlighter
Dim Anno As GdPicture.AnnotationRectangleHighlighter
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationRectangleHighlighter)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationRectangleHighlighter"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeRubberStamp
Dim Anno As GdPicture.AnnotationRubberStamp
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationRubberStamp)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationRubberStamp"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeStickyNote
Dim Anno As GdPicture.AnnotationStickyNote
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationStickyNote)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationStickyNote"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeText
Dim Anno As GdPicture.AnnotationText
Anno = DirectCast(imageViewer.GetAnnotationFromIdx(i), GdPicture.AnnotationText)
info = Anno.GetType().GetProperties()
Anno1 = Anno
Type = "AnnotationText"
Case GdPicture.Annotation.GdPictureAnnotationType.AnnotationTypeUndefined
Continue For
End Select
Dim strOut As String = ""
For x = 0 To UBound(info)
If x > 0 Then strOut &= "||"
strOut &= info(x).Name & "^^" & info(x).GetValue(Anno1, Nothing).ToString
Next
AllAnnos &= "**Page:" & PageNo & "&&Type=" & Type & "##" & strOut
Next
Next
Who is online
Users browsing this forum: No registered users and 1 guest