![]() Original |
![]() Altered Palette |
In this example each palette entry is replaced with a gray tone representing the brightest of the RGB components. This is not a true grayscale, but gives the appearance of grayscale. To create a true grayscale image use the colortogray function in the Victor Library.
' ........... Defines and declarations ........... Type RGBQUAD rgbBlue As Byte rgbGreen As Byte rgbRed As Byte rgbReserved As Byte End Type Declare Function updatebitmapcolortable Lib "VIC32.DLL" (image As imgdes) As Long Declare Sub CopyPaletteFromImagetoRGBArray Lib "kernel32" Alias "RtlMoveMemory" (ByRef desarrayelement As RGBQUAD, ByVal paletteaddress As Long, ByVal cnt As Long) Declare Sub CopyPaletteFromRGBArraytoImage Lib "kernel32" Alias "RtlMoveMemory" (ByVal paletteaddress As Long, ByRef srcarrayelement As RGBQUAD, ByVal cnt As Long) ' ........... The function ........... Public Function changethepalette(ByRef myimage As imgdes) As Long Dim rcode As Long Dim j As Integer Dim colours As Long Dim mypalette(0 To 255) As RGBQUAD Dim red As Byte Dim grn As Byte Dim blu As Byte Dim newcolor As Byte colours = myimage.colors ' Copy the image palette into my local palette CopyPaletteFromImagetoRGBArray mypalette(0), myimage.palette, colours * 4 For j = 0 To (colours - 1) blu = mypalette(j).rgbBlue grn = mypalette(j).rgbGreen red = mypalette(j).rgbRed ' ............... manipulate the palette ................... ' Pick the brightest colors and create a palette of grays newcolor = blu If (red > newcolor) Then newcolor = red End If If (grn > newcolor) Then newcolor = grn End If blu = newcolor grn = newcolor red = newcolor ' ........................................................... ' insert the new palette entries mypalette(j).rgbBlue = blu mypalette(j).rgbGreen = grn mypalette(j).rgbRed = red Next j CopyPaletteFromRGBArraytoImage myimage.palette, mypalette(0), colours * 4 rcode = updatebitmapcolortable(myimage) changethepalette = rcode End Function
Victor Image Processing Library homepage | Victor Product Summary | more source code