/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance /// that represents an off-screen image that was loaded /// from a file.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen upon which to create the new pixmap.</para> /// </param> /// /// <param name="filename"> /// <para>The file to load the image from.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>The <paramref name="filename"/> parameter is /// <see langword="null"/>.</para> /// </exception> /// /// <exception cref="T:System.FormatException"> /// <para>The image format is not recognized.</para> /// </exception> /// /// <exception cref="T:Xsharp.XInvalidOperationException"> /// <para>Raised if <paramref name="filename"/> could not be /// loaded for some reason.</para> /// </exception> public Image(Screen screen, String filename) { Display dpy; if (filename == null) { throw new ArgumentNullException("filename"); } if (screen != null) { dpy = screen.DisplayOfScreen; } else { dpy = Application.Primary.Display; screen = dpy.DefaultScreenOfDisplay; } this.screen = screen; DotGNU.Images.Image img = new DotGNU.Images.Image(); img.Load(filename); Frame frame = img.GetFrame(0); try { dpy.Lock(); pixmapXImage = ConvertImage.FrameToXImage(screen, frame); maskXImage = ConvertImage.MaskToXImage(screen, frame); } finally { dpy.Unlock(); } }
/// <summary> /// <para>Constructs a new <see cref="T:Xsharp.Image"/> instance /// from a <see cref="T:DotGNU.Images.Frame"/> instance.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen upon which to create the new image.</para> /// </param> /// /// <param name="frame"> /// <para>The frame to load the image from.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"> /// <para>The <paramref name="frame"/> parameter is /// <see langword="null"/>.</para> /// </exception> /// /// <exception cref="T:Xsharp.XInvalidOperationException"> /// <para>Raised if <paramref name="filename"/> could not be /// loaded for some reason.</para> /// </exception> public Image(Screen screen, Frame frame) { Display dpy; if (frame == null) { throw new ArgumentNullException("frame"); } if (screen != null) { dpy = screen.DisplayOfScreen; } else { dpy = Application.Primary.Display; screen = dpy.DefaultScreenOfDisplay; } this.screen = screen; try { dpy.Lock(); pixmapXImage = ConvertImage.FrameToXImage(screen, frame); maskXImage = ConvertImage.MaskToXImage(screen, frame); } finally { dpy.Unlock(); } }
/// <summary> /// <para>Create a new cursor, based on a user-supplied image frame.</para> /// </summary> /// /// <param name="screen"> /// <para>The screen to create the cursor for, or /// <see langword="null"/> for the default screen on the /// default display.</para> /// </param> /// /// <param name="frame"> /// <para>The frame defining the cursor image.</para> /// </param> /// /// <exception cref="T:System.ArgumentNullException"/> /// <para>Raised if <paramref name="frame"/> is /// <see langword="null"/>.</para> /// </exception> public Cursor(Screen screen, Frame frame) { Display dpy; if (frame == null) { throw new ArgumentNullException("frame"); } if (screen != null) { dpy = screen.DisplayOfScreen; } else { dpy = Application.Primary.Display; screen = dpy.DefaultScreenOfDisplay; } if ( /* irgnore pixel format! frame.PixelFormat != PixelFormat.Format1bppIndexed || */ frame.Mask == null) { // The frame is not suitable for use as a cursor. this.type = CursorType.XC_left_ptr; this.source = null; this.mask = null; this.cursor = XCursor.Zero; } else { this.type = CursorType.XC_inherit_parent; this.cursor = XCursor.Zero; try { dpy.Lock(); IntPtr pixmapXImage = ConvertImage.FrameToXImageBitmap(screen, frame); IntPtr maskXImage = ConvertImage.MaskToXImage (screen, frame); source = ConvertImage.XImageMaskToBitmap (screen, pixmapXImage); mask = ConvertImage.XImageMaskToBitmap (screen, maskXImage); Xlib.XSharpDestroyImage(pixmapXImage); Xlib.XSharpDestroyImage(maskXImage); hotspotX = frame.HotspotX; hotspotY = frame.HotspotY; if (frame.Palette != null && frame.Palette[0] == 0) { reverse = true; } } finally { dpy.Unlock(); } } }