Panel screencapture is black in invisible part of panel
-
hello tried to make a screencapture of a panel with controls on it and "connections" at the background (created using paint() procedure). DrawToBitmap does only the visible part of the panel, so i came up with the following code after a while. problem is that the invisible part of the panel turns up black in the resulting jpeg picture. Does anyone have any suggestions for me?
protected virtual void mnuRptClicked(object sender, EventArgs e) { this.AutoScrollPosition = new Point(0, 0); // get dimensions int w = 0,h = 0; foreach(Control c in this.Controls ) { if(c.Left + c.Width > w) w = c.Left + c.Width + 100; if(c.Top + c.Height > h) h = c.Top + c.Height + 100; } if(w == 0) w = this.DisplayRectangle.Width; if(h == 0) h = this.DisplayRectangle.Height; // create bitmap Bitmap b = new Bitmap(w,h); Graphics bg = Graphics.FromImage(b); // copy screen to bitmap // TODO: invisible part of screen turns out black int bgHdc = (int)bg.GetHdc(); SendMessage(this.Handle , WM\_PAINT, bgHdc, 0); SendMessage(this.Handle, WM\_PRINT, bgHdc, (int)( DrawingOptions.PRF\_OWNED | DrawingOptions.PRF\_CHILDREN | DrawingOptions.PRF\_CLIENT) ); bg.ReleaseHdc(); bg.Dispose (); // save the result as captured.jpeg b.Save(Application.StartupPath + @"\\captured.jpg", ImageFormat.Jpeg); b.Dispose (); }
-
hello tried to make a screencapture of a panel with controls on it and "connections" at the background (created using paint() procedure). DrawToBitmap does only the visible part of the panel, so i came up with the following code after a while. problem is that the invisible part of the panel turns up black in the resulting jpeg picture. Does anyone have any suggestions for me?
protected virtual void mnuRptClicked(object sender, EventArgs e) { this.AutoScrollPosition = new Point(0, 0); // get dimensions int w = 0,h = 0; foreach(Control c in this.Controls ) { if(c.Left + c.Width > w) w = c.Left + c.Width + 100; if(c.Top + c.Height > h) h = c.Top + c.Height + 100; } if(w == 0) w = this.DisplayRectangle.Width; if(h == 0) h = this.DisplayRectangle.Height; // create bitmap Bitmap b = new Bitmap(w,h); Graphics bg = Graphics.FromImage(b); // copy screen to bitmap // TODO: invisible part of screen turns out black int bgHdc = (int)bg.GetHdc(); SendMessage(this.Handle , WM\_PAINT, bgHdc, 0); SendMessage(this.Handle, WM\_PRINT, bgHdc, (int)( DrawingOptions.PRF\_OWNED | DrawingOptions.PRF\_CHILDREN | DrawingOptions.PRF\_CLIENT) ); bg.ReleaseHdc(); bg.Dispose (); // save the result as captured.jpeg b.Save(Application.StartupPath + @"\\captured.jpg", ImageFormat.Jpeg); b.Dispose (); }
-
Use PrintWindow instead.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)PrintWindow only gives me the visible part of the panel, and it also gives me the scrollbars !
-
PrintWindow only gives me the visible part of the panel, and it also gives me the scrollbars !
-
Sorry I didnt realise you were in a scrollable panel, I thought you were trying to print a window behind some other window, or off screen.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)anyone else a suggestion?