DotImage Knowledgebase

Home : Reverse a 1-bit palette in ImgX
Q10109 - HOWTO: Reverse a 1-bit palette in ImgX

When saving 1-bit TIFF images, some viewers will display the image inverted.  This is caused because a 1-bit TIFF doesn't have a palette, but instead uses a TIFF tag to indicate whether bit 0 = white or black.

This problem can be resolved by correcting the palette so bit 0 = white.  Here is an example of how to correct the palette:

' Make sure a 1-bit palette is correct.
If ix.Image.ImageType = ixitPalette_1 Then
    Dim clr0 As ImgX_Color, clr1 As ImgX_Color
    Set clr0 = ix.Image.Palette.GetEntry(0)
    Set clr1 = ix.Image.Palette.GetEntry(1)
   
    ' clr0 should be white and clr1 should be black.
    If (clr0.Blue + clr0.Green + clr0.Red) < (clr1.Blue + clr1.Green + clr1.Red) Then
        ' The palette needs to be swapped and image data inverted.
        ix.Image.Palette.SetEntry 0, clr1
        ix.Image.Palette.SetEntry 1, clr0
        ix.Filters.Negative
    End If
End If

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
fully answered my question Approved: Monday, June 20, 2005

Powered By InstantKB.NET v1.3
Copyright © 2002, 2013. InstantASP Ltd. All Rights Reserved

preload preload preload