No Control.DrawToBitmap in Compact .NET 3.5?

J

Jo Vermeulen

Hello,

I have converted my project to Compact .NET 3.5 since I need a few of
the features that are only present in this version. However, a feature
I also rely on and which was available on .NET 2.0,
Control.DrawToBitmap, is not included in 3.5 anymore.

I have two questions:


1) Is there a reason why this was removed from the framework?
2) Is there a way to simulate this method's behavior (e.g. rendering a
bitmap from a Control's Graphics object)?

Thanks in advance!

-- Jo Vermeulen
 
J

Jo Vermeulen

Hello,

I have converted my project to Compact .NET 3.5 since I need a few of
the features that are only present in this version. However, a feature
I also rely on and which was available on .NET 2.0,
Control.DrawToBitmap, is not included in 3.5 anymore.

I have two questions:

1) Is there a reason why this was removed from the framework?
2) Is there a way to simulate this method's behavior (e.g. rendering a
bitmap from a Control's Graphics object)?

I thought I found the solution by providing my own Graphics object to
Control.InvokePaint but this method is again only available on .NET
2.0 :-s

-- Jo Vermeulen
 
C

Chris Tacke, eMVP

It wasn't "removed" - it's never existed in the CF. There a re a *lot* of
things not there, as indicated by the 80MB difference in size between the CF
and full FW.

The Smart Device Framework has a mechanism for a full screen shot[1]. For a
single control would be very similar - just using a different source DC.
You could also use the existing method and pass the Control bounds to get a
snapshot of just it.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

[1]
http://www.opennetcf.com/library/sdf/html/2cd50ebd-fd83-134b-c613-891267f8c89c.htm
 
J

Jo Vermeulen

It wasn't "removed" - it's never existed in the CF.  There a re a *lot* of
things not there, as indicated by the 80MB difference in size between the CF
and full FW.

Well, I did notice an inconsistency in the .NET framework
documentation since the list of platforms for Control.DrawToBitmap
includes PocketPC:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.drawtobitmap(VS.80).aspx

While the list of methods DrawToBitmap does not have a PDA icon:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.control_methods(VS.80).aspx

I must have only seen the list of platforms and concluded that the
method was included.
The Smart Device Framework has a mechanism for a full screen shot[1].  For a
single control would be very similar - just using a different source DC.
You could also use the existing method and pass the Control bounds to get a
snapshot of just it.

Perfect, that could solve my problem. I am not sure if I can use the
OpenNETCF assemblies in my project though, since it runs on
Compact .NET 3.5 (and not on Compact .NET 2.0)?

Thanks, I'll give it a try!

-- Jo
 
J

Jo Vermeulen

It wasn't "removed" - it's never existed in the CF.  There a re a *lot* of
things not there, as indicated by the 80MB difference in size between the CF
and full FW.

Well, I did notice an inconsistency in the .NET framework
documentation since the list of platforms for Control.DrawToBitmap
includes PocketPC:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.control...

While the list of methods DrawToBitmap does not have a PDA icon:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.control...

I must have only seen the list of platforms and concluded that the
method was included.
The Smart Device Framework has a mechanism for a full screen shot[1].  For a
single control would be very similar - just using a different source DC.
You could also use the existing method and pass the Control bounds to get a
snapshot of just it.

Perfect, that could solve my problem. I am not sure if I can use the
OpenNETCF assemblies in my project though, since it runs on
Compact .NET 3.5 (and not on Compact .NET 2.0)?

Thanks, I'll give it a try!

Although I managed to get a bitmap of the control, I had to manually
adjust the coordinates. I would think that just using the control's
container's pointtoscreen method would suffice, but apparently the Y
coordinate would then be 26 pixels larger than it should be (the size
of the form's title bar I assume). Is this a bug or am I doing
something wrong?

Here's my code:

private Bitmap ControlToBitmap(Control c)
{
// copy the screen
Bitmap b = new Bitmap(c.Width, c.Height);
GraphicsEx ge =
GraphicsEx.FromGraphics(Graphics.FromImage(b));
int srcX = content.PointToScreen(c.Location).X;
int srcY = content.PointToScreen(c.Location).Y - 26;
int destX = 0;
int destY = 0;
Size size = c.Size;
ge.CopyFromScreen(srcX, srcY, destX, destY, size);

// cleanup
ge.Dispose();

return b;
}

I continually add and remove controls from the container (content),
and take screenshots of them. Sometimes the screenshot seems to
contain part of the previous control. Is there any way to force the
screen to repaint, so I don't have these side effects? Calling
invalidate doesn't seem to help.

The source code for CopyToScreen from OpenNETCF is not available as
far as I see, so I don't know how to copy only the control's into a
bitmap.

Any ideas?

Thanks in advance!

-- Jo
 
J

Jehanzeb Munir

I think its happening because of the title bar. 'PointToScreen' get you the
absolute point from top left. And 'CopyFromScreen' takes coordinates
relatively.
try c.Location.X and c.Location.Y instead of PointToScreen.

Also, I was wondering if your control can also captures the Button control
to Bitmap?
 

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