Another question on CreateDIBSection with Mono DIBs... 
Author Message
 Another question on CreateDIBSection with Mono DIBs...

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



Wed, 23 Mar 2005 15:35:44 GMT  
 Another question on CreateDIBSection with Mono DIBs...

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/




Wed, 23 Mar 2005 16:42:54 GMT  
 Another question on CreateDIBSection with Mono DIBs...
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



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/





Wed, 23 Mar 2005 18:36:49 GMT  
 Another question on CreateDIBSection with Mono DIBs...


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



Wed, 23 Mar 2005 20:32:07 GMT  
 Another question on CreateDIBSection with Mono DIBs...
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


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



Thu, 24 Mar 2005 02:15:11 GMT  
 Another question on CreateDIBSection with Mono DIBs...


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

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

--
Richard Mason



Thu, 24 Mar 2005 14:02:57 GMT  
 
 [ 6 post ] 

 Relevant Pages 

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

2. CreateDIBSection question

3. Question on CreateDIBSection under VB .Net

4. Secondary Mono Monitor in VB4.0?

5. Q: How to record 22khz 16bit mono wavs?

6. I need to record a Wav file at the following format : 8.000 kHz, 16 Bit, Mono

7. I need to record a wave file at 48KHz 16-bit mono with the mciSendString api

8. help with mono bitmap resolution

9. Printing in mono (Part II)

10. Displaying DIBs in an Access 97 report/form

11. HOW TO Save DIBs into AVI

12. Creating DIBs from within VB5

 

 
Powered by phpBB® Forum Software