When converting a small sprite graphic from 24bit color to 4bit color I am using this:
This causes it to convert the 8x8 TrueColor image in the picture box into a 4bitperpixel 8x8 image. But it doesn't use the palette I specified in the Info.bmiColors. Instead GetDIBits overrides the info I manually placed in the palette which was
by replacing it with the windows default palette. When converting any truecolor image into an Indexed Color (palettized color) image, the GetDIBits command is supposed to use the "nearest color" method to find the correct palette. But it ALWAYS USES WINDOWS DEFAULT PALETTE as the palette for conversion. I want to be able to specify my OWN PALETTE (in this case I'm trying for the Commodore 64 color palette). Please help me to set the palette that GetDIBits uses when converting to indexed color images.
Code:
'declares go here
'main code
Dim Info As BITMAPINFO
Dim PixBlock(31) As Byte
With Info.bmiHeader
.biBitCount = 4
.biPlanes = 1
.biWidth = 8
.biHeight = 8
.biSize = 40
.biSizeImage = 32
End With
For n = 0 To 15
Info.bmiColors(n).rgbRed = C64Pal(0, n)
Info.bmiColors(n).rgbGreen = C64Pal(1, n)
Info.bmiColors(n).rgbBlue = C64Pal(2, n)
Next n
GetDIBits Picture1.hdc, Picture1.Image, 0, 8, PixBlock(0), Info, 0
SetDIBits Picture1.hdc, Picture1.Image, 0, 8, PixBlock(0), Info, 0
Code:
For n = 0 To 15
Info.bmiColors(n).rgbRed = C64Pal(0, n)
Info.bmiColors(n).rgbGreen = C64Pal(1, n)
Info.bmiColors(n).rgbBlue = C64Pal(2, n)
Next n