davidrobin
Active member
- Joined
- Jun 24, 2003
- Messages
- 41
Can anyone transpose this VB6 code I got off another forum to .NET code for me.
Code:
module code
Option Explicit
types for palette creation
Public Type PALETTEENTRY
peRed As Byte
peGreen As Byte
peBlue As Byte
peFlags As Byte
End Type
Public Type LOGPALETTE
palVersion As Integer
palNumEntries As Integer
palPalEntry(255) As PALETTEENTRY
End Type
Is used to create a logical palette.
Public Declare Function CreatePalette Lib "gdi32" (lpLogPalette As LOGPALETTE) As Long
Will return the palette index of the nearest color to crColor in hPalette.
Public Declare Function GetNearestPaletteIndex Lib "gdi32" (ByVal hPalette As Long, ByVal crColor As Long) As Long
Public Pal As LOGPALETTE
Public hPal As Long handle to the palette(will be set = createpalette)
form code
Private Sub Form_Load()
Dim x As Long
Pal.palNumEntries = 10
Pal.palVersion = &H300 defines our palette entries and type of palette
define the colors in the palette
Pal.palPalEntry(1).peRed = 1
Pal.palPalEntry(1).peGreen = 2
Pal.palPalEntry(1).peBlue = 3
Pal.palPalEntry(2).peRed = 255
Pal.palPalEntry(2).peGreen = 255
Pal.palPalEntry(2).peBlue = 255
When youve set the colors in the palette, you now do:
hPal = CreatePalette(Pal)
x = GetNearestPaletteIndex(hPal, vbRed)
now to retieve the palettes approximate of somecolor
Dim r As Long: r = Pal.palPalEntry(x).peRed
Dim g As Long: g = Pal.palPalEntry(x).peGreen
Dim b As Long: b = Pal.palPalEntry(x).peBlue
MsgBox r & " " & g & " " & b
x = GetNearestPaletteIndex(hPal, vbWhite)
now to retieve the palettes approximate of somecolor
r = Pal.palPalEntry(x).peRed
g = Pal.palPalEntry(x).peGreen
b = Pal.palPalEntry(x).peBlue
MsgBox r & " " & g & " " & b
End Sub
Last edited by a moderator: