all groups > dotnet compact framework > october 2005 >
You're in the

dotnet compact framework

group:

Get dc of a bitmap


Get dc of a bitmap climax!
10/31/2005 9:30:17 AM
dotnet compact framework:
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.
Re: Get dc of a bitmap climax!
10/31/2005 9:45:18 AM
thanx for the fast reply. Is it possible to use SelectObject with a
embedded C# bitmap object as argument?
Re: Get dc of a bitmap climax!
10/31/2005 10:22:44 AM
thanks, everything is clear now...It seems I will have to place those
bitmaps in a control, copy them and close the control :).
Re: Get dc of a bitmap Paul G. Tobey [eMVP]
10/31/2005 10:39:38 AM
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.

[quoted text, click to view]

Re: Get dc of a bitmap Paul G. Tobey [eMVP]
10/31/2005 11:06:32 AM
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.

[quoted text, click to view]

Re: Get dc of a bitmap Sergey Bogdanov
10/31/2005 8:00:28 PM
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


--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com


[quoted text, click to view]
AddThis Social Bookmark Button