Get dc of a bitmap

C

climax!

Hi!

I am writing a custom scrollbar which will be partly transparent.
Everthing runs ok, I imported some functions from the gdi(like
transparentimage() etc)... but i can't find a way to get a DC from a
Bitmap object(loaded from resources) which is necessary for the gdi
methods. Now, I thought about displaying the bitmap in a hidden
control(child window), take its hwnd and then get it's DC... this
should work but seems not to be a very elegant solution. Does anybody
has an other idea?

thanx.
 
P

Paul G. Tobey [eMVP]

You can't get a DC *from* a bitmap. A DC references some sort of drawing
surface. You'd have to create one with CreateDC, CreateCompatibleDC or a
similar API call. If you do create one, you can then SelectObject a bitmap
into that and any drawing that is done to that DC will be done onto the
bitmap. Look up CreateCompatibleDC(), CreateCompatibleBitmap(), CreateDC(),
SelectObject() in the SDK help for whatever device type you are using.

Paul T.
 
C

climax!

thanx for the fast reply. Is it possible to use SelectObject with a
embedded C# bitmap object as argument?
 
S

Sergey Bogdanov

An Image class has the static method GetHowFromImage. The "How" that
returned from this method is a reference to internal CF structure. The
structure is internal and can be changed in the next CF version (not
tested it in CF 2.0). The description about "How" structure can be found
in the Alex Feinman's article:
http://www.opennetcf.org/PermaLink.aspx?guid=fd194f13-d816-463e-ac95-a467a6293f0b

Briefly, this structure indeed consists of hMemoryDC, hBitmap and some
other fields. I used the hMemoryDC from this structure for the fast
BitBlt'iting from offscreen buffer in this example:
http://www.sergeybogdanov.com/Samples/PictureRotating.zip
 
P

Paul G. Tobey [eMVP]

Not with a pointer to a managed code object, no. You'd have to get the
native handle to that bitmap and pass that handle. As I recall, there's no
way to get that handle in .NET CF 1.0, but there's BitmapEx in OpenNETCF...

Paul T.
 
C

climax!

thanks, everything is clear now...It seems I will have to place those
bitmaps in a control, copy them and close the control :).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top