Displaying DIB's

Displaying DIB's

Post by Jim Deutc » Tue, 09 Mar 1999 04:00:00

Sounds like the BITMAPFILEHEADER has been stripped from these DIBs, and
they start directly with the BITMAPINFO data (after the size DWORD).

If they might be different color depths, then you should read the data
into a BITMAPINFOHEADER structure to find the color depth, then go back
to the start and read it into a BITMAPINFO structure with the proper
palette length.  When you've filled that up, the rest goes into a byte
array.  You can now display it in a picturebox using SetDIBits() API

The picturebox must be _exactly_ the right size (not incl. borders),
with ScaleMode = pixel, and AutoRedraw should be true unless you want
to call SetDIBits() in every paint event.

Or you can write it out to disk and make a bmp file out of it by
stripping off that DWORD (four bytes) and replacing it with

Private Type BITMAPFILEHEADER    '14 bytes
   bfType As Integer
   bfSize As Long
   bfReserved1 As Integer
   bfReserved2 As Integer
   bfOffBits As Long
End Type

bfType = &H4D42
bfSize = the DWORD value + 14 (or 10? if the DWORD includes itself)
bfOffBits = 40

Jim Deutch

Quote:> I want to display a preview image which is stored in an OLE2 file as
> DIB. I managed to get the DIB into an array, but I'm stuck now
> a picture box to display it. The problem is IMHO, that the DIB is
> stored not quite right. Supposedly a DIB should look like this: "BM",
> Header with size and eventually color palette, data.

> The application writes the DIB like this (from their help file):
> "DWORD (data size) followed by continues chunk of memory of that size
> (data).  The data being read can be cast to LPBITMAPINFO which has
> information required to display the bitmap."

> VB's Picture Control or (when saved to a file) CorelPhotoPaint does
> not recognize the format.

> Anybody knowing what I have to do to display this DIB in VB?

> Thanks,

> Marc Fiedler


1. DIB's vs DDB's

We were playing around with options to speed up the graphics in our
application, and up to now all the graphics were real color DIB's.
All the documentation I have read state that for D4 to use DIB's, but
in our playing around we found by changing the handletype to DDB after
loading, DRAMATICALLY improved the speed of the bitmap painting.

I tried to find some additional info on this but had no success.  Any
comments on this?


2. 40 winks

3. Dib Displaying in Windows

4. Exlude object from Light sources

5. DIB to DX8 Display

6. flex render test

7. Displaying a DIB

8. rtf to bmp or wmf or dib

9. Dll returns a Handle to a DIB how can I display in picture box

10. displaying 24 bits DIB bitmap

11. Need Help Creating and Displaying a DIB

12. Displaying DIB ?

13. Displaying A Dib