I have been attempting to put a white top border on an image, adding an annotation and saving.
The basics work well, the problem occurs with the back ground image and combining a bitonal (1-bit tiff). When I combine a colour JPG no inversion.
The new creation and fill work and give a white canvas to work on, but the combine really mucks things up. I have tried many combinations of the CombineCommandFlags and can get all white or all black and inverted but not the normal white background black text.
Any input bitonal does this, I used the barcode1.tif from the Leadtools Images directory to make sure it was not my images causing an issue.
Here is the code that I am using. (VS2008/VB.Net).
Friend Sub exportImage(ByVal sourceFile As String, ByVal destinationFile As String, ByVal annotation As String)
Dim codecs As New RasterCodecs
Dim image As RasterImage
Dim codecInfo As CodecsImageInfo
codecInfo = codecs.GetInformation(sourceFile, True)
Dim byteOrder As New CodecsLoadByteOrder
byteOrder = CType(codecInfo.Order, CodecsLoadByteOrder)
codecs.Options.Load.InitAlpha = True
image = codecs.Load(sourceFile, codecInfo.Width, codecInfo.Height, codecInfo.BitsPerPixel, RasterSizeFlags.None, byteOrder)
'Build the annotation
'
Dim textAnn As New AnnTextObject
Dim annImage As RasterImage
annImage = New RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height + 50, image.BitsPerPixel, image.Order, rasterViewPerspective.TopLeft, Nothing, IntPtr.Zero, 0)
Dim cmdFill As New FillCommand
cmdFill.Color = New RasterColor(Drawing.Color.White)
cmdFill.Run(annImage)
Dim cmdCombine As New CombineCommand
':: Problem appears here ::
' Have tried many variations on
Dim combineFlags As New CombineCommandFlags
combineFlags = CombineCommandFlags.SourceCopy
cmdCombine.Flags = combineFlags
cmdCombine.DestinationRectangle = New Rectangle(0, 50, image.Width, image.Height)
cmdCombine.SourceImage = image
cmdCombine.SourcePoint = New Point(0, 0)
cmdCombine.Run(annImage)
textAnn.Bounds = New AnnRectangle(0, 0, image.Width, 50)
textAnn.TextRotate = AnnTextRotate.Rotate0
textAnn.Alignment = StringAlignment.Center
textAnn.Brush = New AnnSolidBrush(Drawing.Color.Black)
textAnn.EdgeMargin = AnnLength.Empty
textAnn.Font = New AnnFont(FontFamily.GenericMonospace, New AnnLength(48), FontStyle.Bold)
textAnn.LineAlignment = StringAlignment.Center
textAnn.Pen = New AnnPen(Drawing.Color.Black, New AnnLength(5))
textAnn.Text = annotation
textAnn.TextColor = Drawing.Color.White
'We have to burn the annotation via a viewer
'
Dim annViewer As New RasterImageViewer
annViewer.Image = annImage
Dim annManager As New AnnAutomationManager
Dim annAuto As New AnnAutomation(annManager, annViewer)
annAuto.Container.Objects.Add(textAnn) 'add the annotation to the images container
annAuto.Realize() 'burn the annotation to the image
annImage = annViewer.Image
'What format is the file being saved in, assume defaults for now i.e. what we read in
'
Dim imageFormat As RasterImageFormat
Dim bitsPerPixel As Integer
Dim pageMode As CodecsSavePageMode
imageFormat = codecInfo.Format
bitsPerPixel = codecInfo.BitsPerPixel
pageMode = CodecsSavePageMode.Overwrite
'What format do we want to save in
'
If bitsPerPixel = 1 Then
imageFormat = RasterImageFormat.CcittGroup4
Else
imageFormat = RasterImageFormat.TifJpeg411
End If
codecs.Save(annImage, destinationFile, imageFormat, bitsPerPixel, 1, 1, 1, pageMode)
'Clean up
'
image.Dispose()
annImage.Dispose()
codecInfo.Dispose()
codecs.Dispose()
End Sub