[Mono-list] screen capturing in mono
Eric Morgan
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.
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
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
maxHeight)
{
try
{
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
();//this.CreateGraphics();
Bitmap MyImage = new Bitmap(w, h, g1);
System.Drawing.Graphics g2 =
System.Drawing.Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, w, h, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
//Separate dialog to display the image. If I comment out the BitBlt code,
it just appears blank.
Library.Windows.Dialogs.ScreenCaptureDlg dlg = new
Library.Windows.Dialogs.ScreenCaptureDlg(MyImage);
dlg.ShowDialog();
return MyImage;
}
catch(Exception error)
{
//our exception handling library.
Library.Common.ErrMsg.Err( error );
throw 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?
>
> -Abe
>
> 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
> our
> > .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
> into
> > the bitmap. This requires a P/Invoke into gdi32.dll, which obviously
> blows
> > up in mono. Is there a good way to do this using mono? Some other
> library
> > maybe?
> >
> > I've tried installing wine and using the gdi32.dll.so that comes with
> it,
> > but I don't know if I'm using it correctly or not. It can find the
> library,
> > 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...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070228/1faddab6/attachment-0001.html
More information about the Mono-list
mailing list