8 to 24 
Author Message
 8 to 24

Hi all.

Lets assume I have a BitMap image and there are 8 bits per pixel, I have my
BITMAPINFOHEADER and 1024 bytes of colour info for a 32 X 32 image.
Is there a way of getting the 24 bit colour that will be displayed if using
the SetDIBitsToDevice Api. I can do it by creating DCs and bitmaps and
applying the bits then checking the colour of the Pixel (GetPixel Api), but
is there a way of doing this without using the APIs to create pictures and
DCs first.

Thanks for any pointers for this

Ivar



Mon, 31 Oct 2011 05:24:57 GMT  
 8 to 24

Quote:

> Hi all.

> Lets assume I have a BitMap image and there are 8 bits per pixel, I
> have my BITMAPINFOHEADER and 1024 bytes of colour info for a 32 X
> 32 image. Is there a way of getting the 24 bit colour that will be
> displayed if using the SetDIBitsToDevice Api. I can do it by
> creating DCs and bitmaps and applying the bits then checking the
> colour of the Pixel (GetPixel Api), but is there a way of doing
> this without using the APIs to create pictures and DCs first.

> Thanks for any pointers for this

The 1024 bytes would be a table that the 8-bit pixel value indexes.
That probably makes the entries 16 bits each, or 5-6-5 color. The
system should use those as the high-order bits of an 8-8-8 (24 bit
RGB) color.

Just speculation though. I'm sure an expert will be along any second.
(-:

--
        Jim



Mon, 31 Oct 2011 06:00:01 GMT  
 8 to 24



Quote:
> The 1024 bytes would be a table that the 8-bit pixel value indexes.
> That probably makes the entries 16 bits each, or 5-6-5 color. The
> system should use those as the high-order bits of an 8-8-8 (24 bit
> RGB) color.

8Bit per Pixel gives 256 different ColorIndexes (duh...<g>),
which then point into the 256 * 4Bytes (32Bit per Color)
Lookup-Table.
This 1024 Byte large Lookup-Table is organized in a
"plain way" - one Color after the other, so no Channel-
splitting here:

BGRA|BGRA|BGRA|...etc.
and the above BGRA-sequence 256 times.

One can read that into a VB-Array with that structure:
Type BGRA
    B as Byte
    G as Byte
    R as Byte
    A as Byte
End Type

Dim LUT256(0 to 255) As BGRA

then Move-Memory from the End of the DIB into
LUT256(0) and the Colors are available in the App.

Olaf



Mon, 31 Oct 2011 06:12:56 GMT  
 8 to 24

Quote:
> Hi all.

> Lets assume I have a BitMap image and there are 8 bits per pixel, I have
> my BITMAPINFOHEADER and 1024 bytes of colour info for a 32 X 32 image.
> Is there a way of getting the 24 bit colour that will be displayed if
> using the SetDIBitsToDevice Api. I can do it by creating DCs and bitmaps
> and applying the bits then checking the colour of the Pixel (GetPixel
> Api), but is there a way of doing this without using the APIs to create
> pictures and DCs first.

Search MSDN Library for "Bitmap Header Types" using the Search tab and by
titles only.


Mon, 31 Oct 2011 10:36:46 GMT  
 8 to 24

Quote:
> Search MSDN Library for "Bitmap Header Types" using the Search tab and by
> titles only.

The above doesn't give the file format. For file format, search for "Bitmap
Storage".


Mon, 31 Oct 2011 11:08:27 GMT  
 8 to 24
See this sample, which reads BMP files and manipulate them directly:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=3...



Mon, 31 Oct 2011 11:18:28 GMT  
 8 to 24
Thanks for the replies so far.
To demo my problem I've put a bit of code below, add a command button on a
form and paste the code.

The question is:
How to know what long colour will windows draw for each bye value

Thanks

Ivar

The Code:

Option Explicit
Private Declare Function SetDIBitsToDevice Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, _
ByVal y As Long, ByVal dx As Long, ByVal dy As Long, _
ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, _
ByVal NumScans As Long, Bits As Any, BitsInfo As Any, _
ByVal wUsage As Long) As Long

Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, ByVal y As Long) As Long

Private Type BITMAPINFOHEADER
   biSize As Long
   biWidth As Long
   biHeight As Long
   biPlanes As Integer
   biBitCount As Integer
   biCompression As Long
   biSizeImage As Long
   biXPel{*filter*}eter As Long
   biYPel{*filter*}eter As Long
   biClrUsed As Long
   biClrImportant As Long
End Type

Private Sub Command1_Click()
Dim TheHeader As BITMAPINFOHEADER
Dim I As Integer
Dim TheBytes(1023) As Byte
'Create a BitMap header
With TheHeader
.biClrUsed = 256
.biBitCount = 8
.biHeight = 32
.biWidth = 32
.biPlanes = 1
.biSize = 40
End With
'Asign random values for random colours
For I = 1 To 1023
TheBytes(I) = Int(225 * Rnd)
Next
'How to know what colour (Long) will be drawn without
'the following code
Me.ScaleMode = vbPixels
Me.AutoRedraw = True
SetDIBitsToDevice Me.hdc, 0, 0, _
32, 32, 0, 0, 0, 32, TheBytes(0), TheHeader, 0&
Me.Refresh
'Find long value of colour at top right corner
'The last pixel to be drawn, Byte index 1023
Me.Caption = TheBytes(1023) & " = " & GetPixel(Me.hdc, 0, 31)
End Sub



Mon, 31 Oct 2011 15:11:07 GMT  
 8 to 24



Quote:
> The question is:
> How to know what long colour will windows draw for
> each bye value

Adjusted your Code somewhat and made some comments
inside.

'***Into a Form, then click the Form
Option Explicit

Private Declare Function SetDIBitsToDevice Lib "gdi32" _
  (ByVal hdc As Long, ByVal x As Long, _
  ByVal y As Long, ByVal dx As Long, ByVal dy As Long, _
  ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, _
  ByVal NumScans As Long, Bits As Any, BitsInfo As Any, _
  ByVal wUsage As Long) As Long

Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

Private Type BGRA
  B As Byte
  G As Byte
  R As Byte
  A As Byte
End Type

Private Type BITMAPINFOHEADER_WithPalette
   biSize As Long
   biWidth As Long
   biHeight As Long
   biPlanes As Integer
   biBitCount As Integer
   biCompression As Long
   biSizeImage As Long
   biXPel{*filter*}eter As Long
   biYPel{*filter*}eter As Long
   biClrUsed As Long
   biClrImportant As Long
   Palette(0 To 255) As BGRA
End Type

Private Sub Form_Click()
Dim i As Long, TheHeader As BITMAPINFOHEADER_WithPalette
Dim PxlArr(0 To 31, 0 To 31) As Byte 'these are your Pixels(only Indexes)

  'Create a BitMap header
  With TheHeader
    .biClrUsed = 256
    .biBitCount = 8
    .biHeight = -32 'DIBs are "bottom-up", a neg. height ensures a flip
    .biWidth = 32
    .biPlanes = 1
    .biSize = 40

    'Define some Colors, ranging only from black to "pure blue"
    For i = 0 To 255
      With .Palette(i)
        .B = i
      End With
    Next i
  End With

  'since the above was only a Color-Definition, we now have
  'to define, which of the 256 different "darkened blue"
  'indices we want to choose in our small 32x32 Bitmap
  Dim x As Long, y As Long
  For y = 0 To UBound(PxlArr, 2)
    For x = 0 To UBound(PxlArr, 1)
      'let's try something like a "diagonal gradient"...
      'but keep in mind, these are only indices, not the colors...
      'though - the higher the index, the more blueish it gets
      PxlArr(x, y) = (x + 1) * (y + 1) / (32 * 32) * 255
    Next x
  Next y

  'now draw what we have
  If Not AutoRedraw Then AutoRedraw = True
  SetDIBitsToDevice hdc, 0, 0, 32, 32, 0, 0, 0, 32, _
                    PxlArr(0, 0), TheHeader, 0&
  Refresh

  'How to know what colour (Long) will be drawn...?
  Dim ColorBottomRightPxl As Long
  With TheHeader.Palette(PxlArr(31, 31)) 'PxlArr points into the palette
    ColorBottomRightPxl = RGB(.R, .G, .B)
  End With

  'small test:
  Caption = Hex(ColorBottomRightPxl) & " " & Hex(GetPixel(hdc, 31, 31))
End Sub

Olaf



Mon, 31 Oct 2011 22:17:17 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. IMAGELIST and 24 by 24 bit icons...

2. Expressing multiple days as over 24 hours

3. Online Chats: Week of May 20-24

4. How to plot events over a 24 hr timeline

5. 24 digit software lock codes...

6. 24/7 Employee Schedule

7. Why does 24*60*60 = overflow ?

8. Calculating time values >24 HOURS

9. outlook 2000 programming in 24 hours.

10. Time format : 12 h or 24 h

11. sams teachyourself ms word 2000 automation in 24 hours

 

 
Powered by phpBB® Forum Software