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 : Monday, August 10, 2009 1:31:39 AM(UTC)
DSchakel

Groups: Registered
Posts: 2


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


 

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, August 10, 2009 6:17:51 AM(UTC)

Basel  
Guest

Groups: Guests
Posts: 3,034

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

This happens because the 2 images (image and annImage) have different palettes.
To fix the problem, instead of passing Nothing as the Palette to the RasterImage initializing, pass image.GetPalette() so your code looks like this:
annImage = New RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height + 50, image.BitsPerPixel, image.Order, RasterViewPerspective.TopLeft, image.GetPalette(), IntPtr.Zero, 0)
 
#3 Posted : Monday, August 10, 2009 9:13:24 PM(UTC)
DSchakel

Groups: Registered
Posts: 2


Hi Basel,

This mostly works.

I am putting file information in the extra space that I am creating.  Usually this is at the top but it is parameter driven so the user can choose Top, Left, Right or Bottom. 

When I choose Top, Left or Right I get a black bar (even though I do a fill with white [I have also tried black]) and therefore I must change the text to white, however when I select Bottom I get a white bar and must select black text.

The one difference that I think might be causing the problem has to do with the top edge. That is when I combine the images for Bottom the merge cooordinates are 0,0, imageWidth i.e. covering the full top edge, but with the others they are either down 50 or leave a 50 pixel border left or right from the top edge.

Cheers,
Derek.
 
#4 Posted : Tuesday, August 11, 2009 5:06:10 AM(UTC)

Basel  
Guest

Groups: Guests
Posts: 3,034

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

Derek,
If you want the text bar's background to be white and the text to be black, do as follows:
1. Fill with white.
2. Make the brush color white.
3. Make the text color black.

I did this and got a white bar with black text. If you also want the pen to be white set it to white.

Here's the code I changed:
cmdFill.Color = New RasterColor(Drawing.Color.White)
textAnn.Brush = New AnnSolidBrush(Drawing.Color.White)
textAnn.TextColor = Drawing.Color.Black


 
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.130 seconds.