AppFzx
AppFzx

Reputation: 1465

How to get the bitmap from a Graphics object in C#?

How do you get a bitmap from a graphics object (or at least a pointer to it's Scan0)?

If a graphics object really always refers to a bitmap, then it IS possible to get to the bitmap data from the graphics object. (Think: the graphics object HAS TO have a pointer to the bmp data. I'd code it in C but I'm on a project that requires everyone be hobbled by .NET.)

Applications of this would include things like: - using unsafe code to obtain faster screenshots - modifying what's on a control using CreateGraphics - (and the task I'm actually trying to accomplish which would take too long to explain)

Yes, this has been asked before but never answered. I'm not looking for how to get a graphics object from a bitmap (obviously trivial). FAIL1, FAIL2, FAIL3, FAIL4, FAIL5, FAIL6, FAIL7

Upvotes: 0

Views: 699

Answers (1)

Still.Tony
Still.Tony

Reputation: 1434

I don't think what you're trying to do is possible since your assumption that "a graphics object really always refers to a bitmap" is false.

There's a good article here that shows how to render a control to bitmap if you really want a bitmap and another one here that shows how to quickly update the screen at the WndProc level. If you're more familiar with C++ that might get you going the right direction.

Upvotes: 2

Related Questions