Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



Capture Screens with GdiPlus-X

To capture a screen with Gdiplus-X is a very easy task too.
Basically, all we need to do is to call the FromScreen() method from the Bitmap class. To ease this task, this method brings some different overloads.

 

IMPORTANT:

All samples below use the new GDIPlus-X library, that is still in ALPHA version, but is already stable and reliable to do the majority of GDI+ tasks. Download the latest stable release from Codeplex:

http://www.codeplex.com/Wiki/View.aspx?ProjectName=VFPX&title=GDIPlusX

 

1 - Capture a Form Screen sending the hWnd of the form or the form as an object

DO LOCFILE("System.App")

LOCAL loCaptureBmp AS xfcBitmap
WITH _Screen.System.Drawing
   loCaptureBmp = .Bitmap.FromScreen(Thisform.HWnd)
   * Could be also:
   * loCaptureBmp = _screen.system.Drawing.Bitmap.FromScreen(Thisform)

   loCaptureBmp.Save("c:\Captured.png", .Imaging.ImageFormat.Png)
ENDWITH


2 - Capture the whole screen
In this case, no parameter is needed to be passed

DO LOCFILE("System.App")

LOCAL loCaptureBmp AS xfcBitmap
WITH _Screen.System.Drawing
   loCaptureBmp = .Bitmap.FromScreen()
   loCaptureBmp.Save("c:\CapturedScreen.png", .Imaging.ImageFormat.Png)
ENDWITH


3 - Capture the screen of a form cutting off its borders and title.
For this task we use the SYSMETRIC() function to obtain the measure of the screen elements, such as the title height, top and left borders. Then we use another overload, sending the hWnd, and the coordinates of the form to be captured.

DO LOCFILE("System.App")

LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder
lnTitleHeight = SYSMETRIC(9)
lnLeftBorder = SYSMETRIC(3)
lnTopBorder = SYSMETRIC(4)

LOCAL loCaptureBmp AS xfcBitmap

WITH _Screen.System.Drawing
   loCaptureBmp = .Bitmap.FromScreen(;
      Thisform.HWnd, ;
      lnLeftBorder, ;
      lnTitleHeight + lnTopBorder, ;
      Thisform.Width, ;
      Thisform.Height)

      loCaptureBmp.Save("c:\Captured.png", .Imaging.ImageFormat.Png)
ENDWITH


4 - Capture all forms in the screen.
This is very simple too. Just create a loop through all _screen forms and capture each of them, sending the form.hWnd as a parameter.

DO LOCFILE("System.App")

LOCAL loCaptureBmp AS xfcBitmap
LOCAL n
LOCAL loForm AS Form
n = 1

WITH _Screen.System.Drawing

FOR EACH loForm IN _Screen.Forms
   loCaptureBmp = .Bitmap.FromScreen(loForm.HWnd)
   loCaptureBmp.Save("c:\CapturedForm" + TRANSFORM(n) + ".png", ;

      .Imaging.ImageFormat.Png)
   n = n + 1
ENDFOR

ENDWITH

Published Wednesday, January 17, 2007 1:36 PM by cesarchalom
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

LuisMaria said:

Este articulo esta traducido al español en www.PortalFox.com

"Capturando pantallas con GdiPlus-X"
http://www.portalfox.com/article.php?sid=2346
July 11, 2007 9:18 PM
 

Garrett Fitzgerald said:

Hey, Cesar. How would you capture a BMP if you wanted to be able to tweak the alpha? Thanks.

Hi Garret,

What exactly do you mean here ? Can you send a sample showing what you need here ?

Regards

Cesar

November 15, 2007 9:07 PM
 

VFP IMAGING said:


 
The GdiPlusX library is intended to be compatible with the .NET Framework’s System.Drawing...
May 26, 2008 6:59 PM
 

gruperez said:

Thank you and i just used it in replacement of my DDE general function.

Regards,

gino
Saudi Arabia
June 25, 2008 4:07 PM

What do you think?

(required) 
(optional)
(required)