Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple example on how to create a Bitmap Top-Down

215 views
Skip to first unread message

Asger Joergensen

unread,
Dec 20, 2007, 6:19:48 PM12/20/07
to
Hi there

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

Remy Lebeau (TeamB)

unread,
Dec 20, 2007, 8:15:48 PM12/20/07
to

"Asger Joergensen" <ju...@Asger-P.dk> wrote in message
news:MPG.21d517048...@newsgroups.borland.com...

> I have been looking at CreateDIBitmap, but I can't figure
> out how to use it.

What exactly is unclear about it?


Gambit


Asger Joergensen

unread,
Dec 21, 2007, 4:31:56 AM12/21/07
to

Hi Remy

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




Asger Joergensen

unread,
Dec 21, 2007, 4:39:20 AM12/21/07
to

Forgot to say tht my plan is to give the HBITMAP handle
to a TBitmap so I can use it in my tests.

when I do that does TBitmap free the HBITMAP ?

Kind regards
Asger

JD

unread,
Dec 22, 2007, 12:39:39 AM12/22/07
to

Asger Joergensen <ju...@Asger-P.dk> wrote:
>
> Forgot to say tht my plan is to give the HBITMAP handle
> to a TBitmap so I can use it in my tests.
>
> when I do that does TBitmap free the HBITMAP ?

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

Asger Joergensen

unread,
Dec 22, 2007, 8:21:17 AM12/22/07
to

Hi 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

JD

unread,
Dec 22, 2007, 12:43:35 PM12/22/07
to

Asger Joergensen <ju...@Asger-P.dk> wrote:
>
>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..

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

Remy Lebeau (TeamB)

unread,
Dec 22, 2007, 4:23:55 PM12/22/07
to

"JD" <nos...@nospam.com> wrote in message
news:476cb12b$1...@newsgroups.borland.com...

> 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


Remy Lebeau (TeamB)

unread,
Dec 22, 2007, 4:30:22 PM12/22/07
to

"JD" <nos...@nospam.com> wrote in message
news:476d5ad7$1...@newsgroups.borland.com...

> 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


Jonathan Benedicto

unread,
Dec 25, 2007, 1:57:33 PM12/25/07
to
Asger Joergensen wrote:
> 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.

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


Asger Joergensen

unread,
Dec 26, 2007, 11:30:14 AM12/26/07
to

Hi Jonathan


Jonathan Benedicto says:
>
> Try this:
>
> HBITMAP BmpHandle;
> BITMAPINFO bmi;
> void *data = NULL;
> ......

Thank You very much, just what I was looking for, never
thought it would be that simple.

Thanks again
Kind regards
Asger

0 new messages