[Mono-list] screen capturing in mono

Sebastien Pouliot sebastien.pouliot at gmail.com
Mon Mar 5 08:20:27 EST 2007


On Wed, 2007-02-28 at 13:48 -0700, Eric Morgan wrote:
> mmmmmm, open source.  I'll give that a shot, thanks!
> 
> Are there any license restrictions if I do that?  Our code is not open
> source, it's a commercial product.  Should I just include author and
> rights of that code within our source code via comments? 
> 
> I'm only vaguely familiar with the LGPL or GPL licenses...  

Not a problem as the Mono class libraries are MIT X.11 licensed ;-)
http://www.opensource.org/licenses/mit-license.php
and it's one of the easiest license to understand. 

Have fun :-)

> This may be a good opportunity to ask about that, but I feel that it
> should be a separate thread.
> 
> Thanks!
> 
> Eric
> 
> On 2/28/07, Sebastien Pouliot <sebastien.pouliot at gmail.com> wrote:
>         Eric,
>         
>         There's no alternative to p/invoke - even if you used 2.0 you
>         would only
>         be calling a method hiding some platform specific p/invoke
>         calls.
>         
>         Now using 2.0 may not be an option for you, but that doesn't
>         prevent you 
>         from using CopyFromScreen. Why ? because it's open source :-)
>         
>         Just create your own library using Mono source code for
>         CopyFromScreen
>         (and the code it depends on) or include the source in your own
>         project. 
>         
>         Sebastien
>         
>         On Wed, 2007-02-28 at 13:27 -0700, Eric Morgan wrote:
>         > The problem isn't resizing - I don't have an original bitmap
>         to
>         > resize.  The problem is that I have a control that I want a
>         screenshot 
>         > of.  So, I'm trying to create a Bitmap from whatever is
>         appearing in
>         > the control.
>         >
>         > I pass the control in, then I call control.CreateGraphics();
>         > System.Drawing.Graphics g1 = c.CreateGraphics ();
>         >
>         > Then, with the resulting graphics object, I try to create a
>         new
>         > bitmap.
>         > Bitmap MyImage = new Bitmap(w, h, g1);
>         >
>         > The thing is, this bitmap is blank, unless I paste back in
>         that BitBlt 
>         > code.  I can't figure out how to get a new bitmap from a
>         graphics
>         > object, without BitBlt().
>         >
>         > Sebastien - Using 2.0 isn't an option, unfortunately.
>         >
>         > Is there any alternative from P/Invoking in this case? 
>         >
>         > Thanks for all the help!
>         >
>         > Eric
>         >
>         > On 2/28/07, Abe Gillespie <abe.gillespie at gmail.com> wrote:
>         >         It looks like you're just taking the image and
>         resizing it to 
>         >         show in
>         >         the dialog.  You really should not have to go into
>         native OS
>         >         libraries
>         >         to do so.  Does this site help?
>         >
>         >
>         http://www.peterprovost.org/archive/2003/05/29/516.aspx
>         >
>         >         -Abe
>         >
>         >         On 2/28/07, Eric Morgan <eric at rengeo.com> wrote:
>         >         > 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
>         >         > > >
>         >         > > >
>         >         > >
>         >         > >
>         >         >
>         >         >
>         >         > _______________________________________________ 
>         >         > Mono-list maillist  -  Mono-list at lists.ximian.com
>         >         > http://lists.ximian.com/mailman/listinfo/mono-list
>         >         >
>         >         >
>         >
>         >
>         > _______________________________________________
>         > Mono-list maillist  -  Mono-list at lists.ximian.com 
>         > http://lists.ximian.com/mailman/listinfo/mono-list
>         
>         
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list



More information about the Mono-list mailing list