[Mono-dev] Bug in Screen.GetBounds and missing ld-config file after mono 2.10.1 installation from source
Quandary
quandary82 at hailmail.net
Sun Mar 6 18:17:21 EST 2011
Hi,
I'm writing a fully managed remote-desktop clone.
I encountered a problem:
I wanted to take a screenshot in managed code, as described here:
http://jalpesh.blogspot.com/2007/06/how-to-take-screenshot-in-c.html
(first comment for proper code)
Which gets me this on mono 2.6.7 and 2.10.1 (upgraded to 2.10.1 after it
didn't work in 2.6.7):
System.InvalidOperationException: XGetImage returned NULL when asked to
for a 5120x800 region block
If I add (uncomment it, see code at the bottom of this mail)
rectScreenBounds = new System.Drawing.Rectangle(0,0,100,100);
then it works...
So the result of the System.Windows.Forms.Screen.GetBounds rectangle is
certainly wrong.
(It works fine on Windows).
I've got a 1024x768 resolution, 15 inch laptop monitor...
You can get the proper screen bounds in C by getting DisplayHeight and
DisplayWidth from DefaultScreen via X11 with this code:
char *display_name = NULL;
Display* display;
/* open the connection to the display "simey:0". */
display = XOpenDisplay(display_name);// display = XOpenDisplay("simey:0");
if (display == NULL)
{
fprintf(stderr, "Cannot connect to X server %s\n", "simey:0");
exit (-1);
}
int screen_height = DisplayHeight(display, DefaultScreen(display));
int screen_width = DisplayWidth(display, DefaultScreen(display));
printf("This screen is (%d,%d)\n", screen_width, screen_height);
XCloseDisplay( display )
Furthermore, since I already am writing an email, after compiling the
entire mono 2.10.1 suite:
When starting MonoDevelop, I get:
---> System.DllNotFoundException: gtksharpglue-2
But libgtksharpglue-2.so is present in
/usr/lib/cli/gtk-sharp-2.0/libgtksharpglue-2.so
This error occurs because libgtksharpglue-2.so is in a subfolder of
/usr/lib, so this path is NOT in the ld-config paths.
One needs to create a glib.conf file in /etc/ld.so.conf.d/:
gedit /etc/ld.so.conf.d/glib.conf
And then add this text to it
# Mono needs you
/usr/lib/cli/glib-sharp-2.0
And afterwards updating the ld-library paths
/sbin/ldconfig
This needs to be included in the installing subroutine (well, without
using gedit, you know what I mean)
Here my screenshot code:
(Note: it gets called from a timer every 1000/24 = 41 milliseconds)
protected System.Drawing.Rectangle rectScreenBounds =
System.Windows.Forms.Screen.GetBounds(System.Drawing.Point.Empty);
protected System.Drawing.Bitmap bmpScreenshot = new
System.Drawing.Bitmap(1, 1);
//
http://jalpesh.blogspot.com/2007/06/how-to-take-screenshot-in-c.html
private void GetScreenshot()
{
/*
// Do I need to dispose the PictureBox.Image as well ?
if (this.pictureBox1.Image != null)
this.pictureBox1.Image.Dispose();
*/
bmpScreenshot.Dispose();
Console.WriteLine(rectScreenBounds.ToString());
//rectScreenBounds = new System.Drawing.Rectangle(0,0,100,100);
bmpScreenshot = new
System.Drawing.Bitmap(rectScreenBounds.Width, rectScreenBounds.Height);
using (System.Drawing.Graphics g =
System.Drawing.Graphics.FromImage(bmpScreenshot))
{
g.CopyFromScreen(System.Drawing.Point.Empty,
System.Drawing.Point.Empty, rectScreenBounds.Size);
} // End Using g
this.pictureBox1.Image = bmpScreenshot;
} // End Sub GetScreenshot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110307/1c973ea5/attachment-0001.html
More information about the Mono-devel-list
mailing list