Another question on CreateDIBSection with Mono DIBs...

Another question on CreateDIBSection with Mono DIBs...

Post by D. Gree » Sun, 06 Oct 2002 16:35:44



I could find nothing on this in VC++ help or on Google...

When I create a mono DIB using CreateDIBSection, does the API always "clear" the
DIB?
Or is it wise to fill the DIB with the "background" color after creating it?

I've tried it as is and I get a proper cleared DIB.
A FillRect is easy to do though if there are issues with this.

Thanks,
David
lilchips.com

 
 
 

Another question on CreateDIBSection with Mono DIBs...

Post by Mike D Sutto » Sun, 06 Oct 2002 17:42:54


Quote:> I could find nothing on this in VC++ help or on Google...

> When I create a mono DIB using CreateDIBSection, does the API always
"clear" the
> DIB?
> Or is it wise to fill the DIB with the "background" color after creating
it?

> I've tried it as is and I get a proper cleared DIB.
> A FillRect is easy to do though if there are issues with this.

Rather than filling the DIB, use the ZeroMemory() API directly on the image
data which is the fastest way of clearing all the data AFAIK.  Most of the
time it should clear the data for you, but just occasionally (Based on OS /
where you're calling it from perhaps?) it doesn't.  If you modify the
lplpVoid parameter to being ByRef then you'll get the pointer to the data
back then overwrite a byte array descriptor to point it at the DIB data for
clearing it.
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/



 
 
 

Another question on CreateDIBSection with Mono DIBs...

Post by D. Gree » Sun, 06 Oct 2002 19:36:49


Hi Mike,

Thanks again.
I've not had it *not* be properly cleared, but thought I'd check with the ng.
Great tip on using ZeroMemory.  Don't know why I didn't think of that one.

David
lilchips.com



> > I could find nothing on this in VC++ help or on Google...

> > When I create a mono DIB using CreateDIBSection, does the API always
> "clear" the
> > DIB?
> > Or is it wise to fill the DIB with the "background" color after creating
> it?

> > I've tried it as is and I get a proper cleared DIB.
> > A FillRect is easy to do though if there are issues with this.

> Rather than filling the DIB, use the ZeroMemory() API directly on the image
> data which is the fastest way of clearing all the data AFAIK.  Most of the
> time it should clear the data for you, but just occasionally (Based on OS /
> where you're calling it from perhaps?) it doesn't.  If you modify the
> lplpVoid parameter to being ByRef then you'll get the pointer to the data
> back then overwrite a byte array descriptor to point it at the DIB data for
> clearing it.
> Hope this helps,

>     Mike

>  -- EDais --

>  - Microsoft Visual Basic MVP -
> WWW: Http://EDais.earlsoft.co.uk/



 
 
 

Another question on CreateDIBSection with Mono DIBs...

Post by Richard Maso » Sun, 06 Oct 2002 21:32:07




Quote:>When I create a mono DIB using CreateDIBSection, does the API always "clear"
>the
>DIB?
>Or is it wise to fill the DIB with the "background" color after creating it?

I've never had any reason to think it isn't cleared but as, at some
point, you are going to fill it out with useful data anyway does it
matter?

--
Richard Mason

 
 
 

Another question on CreateDIBSection with Mono DIBs...

Post by D. Gree » Mon, 07 Oct 2002 03:15:11


Hi Richard,

This particular implementation is [currently] for a mono print preview system.
When I create the initial DIB section, I set the palette values for black on
white, so the "background" would only necessarily be all white if the API set
all bits in the DIB to 0 when I create it.
I then am only "drawing" black text and lines/rects onto the DIB.  So if it
wasn't always cleared I could end up with some garbage bits on the page.
So long as CreateDIBSection zeros it all, then I'm ok.  However...

I was creating and deleting the DIBSection as each new page was "rendered", but
decided rather to go with simply clearing the DIB on each "NewPage" instead.
This way I don't have to worry about memory allocation issues with each page and
the possible mid-print termination with error, in case the end-user is running
other tasks that happen to be allocating at the same time as the preview render.

BTW, thanks for posting so much good code on the NGs...  I located a bunch of
the useful API code for the DIBs and saving them to file etc. from older posts
of yours now on Google Groups.
This is my first venture into the DIB APIs and all of the code was very helpful.

David
lilchips.com




> >When I create a mono DIB using CreateDIBSection, does the API always "clear"
> >the
> >DIB?
> >Or is it wise to fill the DIB with the "background" color after creating it?

> I've never had any reason to think it isn't cleared but as, at some
> point, you are going to fill it out with useful data anyway does it
> matter?

> --
> Richard Mason

 
 
 

Another question on CreateDIBSection with Mono DIBs...

Post by Richard Maso » Mon, 07 Oct 2002 15:02:57




Quote:>BTW, thanks for posting so much good code on the NGs...

Thanks David. I could listen to that all day :-)

--
Richard Mason

 
 
 

1. BITMAPINFO and CreateDIBSection for Mono DIBs gives color problems...

I wasted a few hours to figure out what was going wrong, but did get it
working...
Anyone want to tell me what VB does that causes this to fail?

  Public Type BITMAPINFO
    bmiHeader   As BITMAPINFOHEADER
    bmiColors() As RGBQUAD
  End Type

  ReDim uBMI.bmiColors(1) As RGBQUAD

  uBMI.bmiColors(0).rgbBlue = 255     ' DIB 0-bits (clear) = White
  uBMI.bmiColors(0).rgbGreen = 255
  uBMI.bmiColors(0).rgbRed = 255
  uBMI.bmiColors(1).rgbBlue = 0       ' DIB 1-bits (set) = Black
  uBMI.bmiColors(1).rgbGreen = 0
  uBMI.bmiColors(1).rgbRed = 0

I'll get random background/foreground colors when I use VB to ReDim the RGBQUAD
array of palette entries.
Is VB allocating the array somewhere out in lala land by using ReDim instead of
keeping it where a pre-allocated definition would have it?

If I preset the structures to "mono" then it works fine:

  Public Type BITMAPINFO_1
    bmiHeader    As BITMAPINFOHEADER
    bmiColors(1) As RGBQUAD
  End Type

However, I also then require aliased versions of my APIs etc. to handle the
color and mono versions of the structures.

Public Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, ByRef
pBitmapInfo As BITMAPINFO, ByVal iUsage As Long, ByVal ppvBits As Long, ByVal
hSection As Long, ByVal dwOffset As Long) As Long

Public Declare Function CreateDIBSectionMono Lib "gdi32" Alias
"CreateDIBSection" (ByVal hDC As Long, ByRef pBitmapInfo As BITMAPINFO_1, ByVal
iUsage As Long, ByVal ppvBits As Long, ByVal hSection As Long, ByVal dwOffset As
Long) As Long

Thanks,
David
lilchips.com

2. Fril?ggning

3. DIBs and packed DIBs

4. MetaPost terminal?

5. Question on CreateDIBSection under VB .Net

6. Map Coloring Project

7. problem with CreateDIBSection

8. Grafik - Problem !!!

9. CREATEDIBSECTION help, URGENT!!

10. Fast 24Bit with CreateDibSection ???

11. problem by parameters for CreateDIBSection

12. CreateDibSection