[Mono-list] screen capturing in mono
eric at rengeo.com
Wed Feb 28 14:27:52 EST 2007
I'm not too sure how to get a Bitmap object from a graphics object. From
all I've read, I just hear that you have to deal with device contexts. I'm
not too familiar with it, but BitBlt seems to be the way to do that. What
would I need to do to get that bitmap created with what appears in the
control using 100% .NET so it can run in mono? Here's a snippet of code.
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
public static Bitmap PerformCapture(Control c, int maxWidth, int
int w = c.ClientRectangle.Width;
int h = c.ClientRectangle.Height;
w = System.Math.Min(w, maxWidth);
h = System.Math.Min(w, maxHeight);
System.Drawing.Graphics g1 = c.CreateGraphics
Bitmap MyImage = new Bitmap(w, h, g1);
System.Drawing.Graphics g2 =
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, w, h, dc1, 0, 0, 13369376);
//Separate dialog to display the image. If I comment out the BitBlt code,
it just appears blank.
Library.Windows.Dialogs.ScreenCaptureDlg dlg = new
//our exception handling library.
Library.Common.ErrMsg.Err( error );
On 2/28/07, Abe Gillespie <abe.gillespie at gmail.com> wrote:
> Are you P/Invoking for performance? Why not just use the GDI .Net API?
> On 2/28/07, Eric Morgan <eric at rengeo.com> wrote:
> > Hi all,
> > Is there a good way to capture screens or something similar in mono? In
> > .NET application, we have custom controls, and we basically create a
> > graphics object from it, make a new bitmap, then do a bitblt to get it
> > the bitmap. This requires a P/Invoke into gdi32.dll, which obviously
> > up in mono. Is there a good way to do this using mono? Some other
> > maybe?
> > I've tried installing wine and using the gdi32.dll.so that comes with
> > but I don't know if I'm using it correctly or not. It can find the
> > but it gives a SIGSEGV while trying to execute the bitblt
> operation. Seemed
> > like kind of a hack, and I didn't really expect it to work... Do I need
> > other libraries along with the gdi32.dll.so ?
> > Any advice is appreciated. Thanks.
> > Eric Morgan
> > Renegade Geophysics
> > 303-661-0400, x2
> > _______________________________________________
> > Mono-list maillist - Mono-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Mono-list