I need a 24 bit Top-Down Bitmap for testing purpose.
(TBitmap create Bottom-Up bitmaps)
I have been looking at CreateDIBitmap, but I can't
figure out how to use it.
Would somebody be so kind and help me with a simple
code example.
Thanks in advance
Asger
> I have been looking at CreateDIBitmap, but I can't figure
> out how to use it.
What exactly is unclear about it?
Gambit
To be honest Remy, almost all of it, You see I have a reading
problem, when ever I go into new areas, evrything is a mess inside
my head and reading the windows help never did me much good,
I simply don't understand there way of thinking.
I need to use an example, to start building some kind of
understanding.
I look at the net, I find examples, hundred lines of code
or more, some aloocate memory some dont, calculating this and that
and my head just gets more and more confused.
I gues You dont know what thats like..;-) You seem to understand
everything just by looking at it (thats the way it is for me in
the practical world).
So please Remy (or somebody else), just a simple example creating
a 24 bit Top-Down Bitmap to get me started.
Thanks in advance
Asger
when I do that does TBitmap free the HBITMAP ?
Kind regards
Asger
No. When you assign an HBITMAP to the TBitmap::Handle, the
TBitmap does not take ownership of the HBITMAP ... the HBITMAP
is copied instead. However, I suspect that your tests will be
fruitless. See my reply in the vcl.using group.
~ JD
But Remy says in the nativeapi group in thread
How to use BitBlt with a HBITMAP handle:
"Assigning an HBITMAP to a TBitmap does not make a copy.
The TBitmap takes ownership of the HBITMAP instead."
So now I'm confused..
Kind regards
Asger
Me too! This is what I recalled to reach my conclusion (from
the help for TBitmap::Handle):
Handle is the HBITMAP encapsulated by the bitmap object.
Avoid grabbing the handle directly since it causes the
HBITMAP to be copied if more than one TBitmap shares the
handle.
There is enough ambiguity there for me to be wrong. I'd say
take Gambit's word for it.
~ JD
> No. When you assign an HBITMAP to the TBitmap::Handle,
> the TBitmap does not take ownership of the HBITMAP ...
> the HBITMAP is copied instead.
That is not true. TBitmap DOES take ownership. Look at the source for
TBitmap::SetHandle() and TBitmap::NewImage().
Gambit
> Avoid grabbing the handle directly since it causes the
> HBITMAP to be copied if more than one TBitmap
> shares the handle.
That is a different issue.
*Assigning* the Handle property takes immediate ownership of the HBITMAP,
and set the reference count for it to 1. Assigning a TBitmap to a TBitmap
increments the reference count.
*Reading* the Handle property (which your quote is referring to) will copy
the HBITMAP internally if the reference count is greater than 1. Otherwise
the original HBITMAP is used instead.
Gambit
Try this:
HBITMAP BmpHandle;
BITMAPINFO bmi;
void *data = NULL;
ZeroMemory( &bmi, sizeof( BITMAPINFO ) );
bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
bmi.bmiHeader.biWidth = 320;
// Create top-down bitmap by specifying a negative height.
bmi.bmiHeader.biHeight = -240;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
BmpHandle = CreateDIBSection( PaintBox1->Canvas->Handle, &bmi,
DIB_RGB_COLORS, &data, NULL, 0 );
if( !BmpHandle )
return;
Graphics::TBitmap *bmp = new Graphics::TBitmap();
bmp->Handle = BmpHandle;
PaintBox1->Canvas->Draw( 0, 0, bmp );
delete bmp;
HTH
Jon
Thank You very much, just what I was looking for, never
thought it would be that simple.
Thanks again
Kind regards
Asger