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



GdiPlusX undocumented functions

 

The GdiPlusX library is intended to be compatible with the .NET Framework’s System.Drawing namespace. That means that you can use the MSDN online documentation for the “System.Drawing” in order to obtain accurate information about the GdiPlusX classes. objects and functions. More than that, you can also convert the huge amount of samples published in various forums, blogs, articles and e-magazines to be used in VFP. It really does not matter if the sample was published in VB, C or ASP. The conversion to VFP is really intuitive.

 

When GdiPlusX was coded, we used a .NET conversion tool, called Reflector, which showed us all the source codes involved in each function, bringing us the possibility to code calling the same API functions, working with the same parameters.

 

 

BUT, during the coding phase, we had some great discussions about things that could be enhanced in order to ease user’s lives.

 

 

We had a premise not changing the behavior of any function, even if we disagreed with some things there, in order to keep the full compatibility.

 

On the other hand, we have decided that we could add new functions

 

 

Below is a short list of some functions that have been added to GdiPlusX, that are not present in the .NET original classes. Most of them have already been used in some samples posted in this blog, but till now, no documentation was published. So, here are some of those new functions, that came to my mind. Probably Bo or Craig will remember to add something here. I hope to be updating this post with some other improvements that only VFP users have available.

 

Of course, we know that GdiPlusX still needs some documentation, and we’re working on it. But for now, we hope that the list below will bring you some help.

 

 

 

 

 

xfcGraphics class

 

DrawStringJustified

 

            Draws the specified text string at the specified location with the specified Brush and Font objects in a Full Justified format.

 

            Parameters: tcString, ;

                        toFont as xfcFont, ;

                        toBrush as xfcBrush, ;

                        toRectangle as xfcRectangle

           

     where:

                        tcString: text to be drawn

                        toFont: Gdi+X font object

                        toBrush: Gdi+X brush object

                        toRectangle: Gdi+X Rectangle object with position and dimensions to draw

 

            Returns: Nothing

            See also: Full-Justified Text with GdiPlus-X

                           Full Justified Texts in your reports with GdiPlus X

 

            GdiPlusX Sample: FullJustified.scx  /  FullJustify.Prg

 

            Code sample:

 

 

LOCAL lcText
TEXT TO
lcText
NOSHOW
This library
was intended to provide Visual FoxPro 9.0 developers with an object based library to wrap the 600+ functions included with the GDI+ API. The intent is to mimic the System.Drawing namespace in the .NET Framework. All classes in the library are based on the classes included in the System.Drawing namespace and other classes that are dependencies for classes in the System.Drawing namespace. Some additional additional functionality has been added to take advantage of features built in to VFP 9.0

ENDTEXT

DO LOCFILE("System.app")
WITH _Screen.System.Drawing
   LOCAL
loGfx as xfcGraphics
   loGfx = .Graphics.FromHwnd(
_Screen.HWnd
)
   loGfx.DrawStringJustified(lcText, .
Font
.New("Tahoma",12);
      , .Brushes.Red, .Rectangle.New(0,0,250,400))
ENDWITH

 

 

 

 

 

xfcBitmap class

 

 

ToClipboard

 

            Sends the current bitmap to the clipboard

 

            Parameters: None

            Returns: Nothing

            See also: Send Images to the Clipboard with GdiPlus-X Revisited

 

            Code sample:

 

DO LOCFILE("System.app")

 
WITH _Screen
.System.Drawing

   LOCAL
loBmp as xfcBitmap
   loBmp = .
Bitmap.FromFile(GETPICT
())
   loBmp.ToClipboard()
ENDWITH

 

 

 

 

 

FromClipboard

 

            Creates a GDI+ bitmap object from the clipboard data

 

            Parameters: None

            Returns: Gdi+ bitmap object

 

            Code sample:

 

DO LOCFILE("System.app")

WITH _Screen.System.Drawing

   LOCAL
loBmp as xfcBitmap
  
loBmp = .
Bitmap
.FromClipboard()
   loBmp.
Save
("c:\FromClip.png", .Imaging.ImageFormat.Png)

ENDWITH

 

 

 

 

FromVarbinary

 

            Creates an Image object from the specified VarBinary string. Useful to start manipulating an image directly without having to convert the binaries from the image to a file.

 

            Parameters: tcBinary

 

            Returns: GdiPlusX Bitmap object

 

            Code sample:

 


DO LOCFILE("System.app")

WITH _Screen.System.Drawing

   LOCAL
lcBinary
   lcBinary =
FILETOSTR(GETPICT
())

   LOCAL
loBmp as xfcBitmap
   loBmp = .
Bitmap
.FromVarBinary(lcBinary)
   loBmp.
Save
("c:\FromVarBinary.png", .Imaging.ImageFormat.Png)

ENDWITH

 

 

 

FromScreen

 

            Captures the specified window or object image to a new GDI+ bitmap object

 

            Parameters:

tHWnd,                 tiX, tiY, tiWidth, tiHeight, tlEnsureVisible

                                toForm [, tiX, tiY, tiWidth, tiHeight [, tlEnsureVisible]]

                               toControl [, tlEnsureVisible]

 

            Returns: Gdi+ bitmap object

 

            See also: Capture Screens with GdiPlus-X

 

            Code sample:

 

 
DO LOCFILE
("System.app")

WITH _Screen
.System.Drawing

   LOCAL
loBmp as xfcBitmap
   loBmp = .
Bitmap.FromScreen()
   loBmp.
Save("c:\FromScreen.png", .Imaging.ImageFormat.Png)

ENDWITH

 

 

 

 

GetMonochrome

 

            Returns a monochrome GDI+ bitmap (1bpp) of this Image object.

            The image must be saved in the BMP Image Format in order to keep the 1bpp format. Because the resulting bitmap is in an indexed pixel format, GDI+ cannot create a xfcGraphics object in order to draw on it. This function is recommended to be used immediately before saving to a file, in order to obtain the minimum file size. For some specific TIFF compression types, a monochrome image of 1bpp is required too, see more details in these articles:

 

            Parameters: None

 

            Returns: Gdi+ bitmap object

 

            See also: Convert Images to Monochrome with GdiPlus X

                        Using TIFFs with the new GDI+ classes - UPDATE

                        TIFFS and the latest release of GdiPlusX

 

            Code sample:

 


DO LOCFILE("System.app")

WITH _Screen
.System.Drawing

   LOCAL
loBmp as xfcBitmap
   loBmp = .
Bitmap.FromFile(GETPICT
())

   LOCAL
loMonoch as xfcBitmap
   loMonoch = loBmp.GetMonochrome()

   loMonoch.
Save
("c:\Monoch.bmp", .Imaging.ImageFormat.Bmp)

ENDWITH

 

 

 

 

GetPictureVal

 

            Returns a String containing the PictureVal of this Image object, according to the ImageFormat passed. You can retrieve the binaries of the image with NO disk access, in any Image format supported by GDI+

 

            Parameters: ImageFormat Object

                                   EncoderParameter Object (optional)

            Returns: String

 

            See also: Manipulate images with no disk access with GdiPlusX

 

            Code sample:

 


DO LOCFILE("System.App")

LOCAL loBmp as xfcBitmap
* Obtaining the PictureVal directly
WITH _Screen
.System
.Drawing 
   loBmp = .Bitmap.FromFile(GETPICT())
   Thisform.Image1.PictureVal = loBmp.GetPictureVal (.Imaging.ImageFormat.Bmp)

ENDWITH

 

 

 

 

GetPictureValFromHBitmap

 

            Returns a String containing the PictureVal of this Image object using the HBitmap GDI technique. The binaries retrieved are always in BMP format, what makes it a big string in most times. But, in most cases, this technique runs about 40% faster than using GetPictureVal() function shown above. The ImageCanvas objects uses this function to obtain the binaries from the images drawn.

 

            Parameters: None

 

            Returns: String

 

            See also: Manipulate images with no disk access with GdiPlusX

 

 


DO LOCFILE("System.App")

LOCAL loBmp as xfcBitmap

* Obtaining the PictureVal directly
WITH _Screen
.System
.Drawing
   loBmp = .
Bitmap.FromFile(GETPICT
())
   Thisform.Image1.PictureVal = loBmp.GetPictureValFromHBitmap()

ENDWITH

 

 

 

 

ApplyColorMatrix

 

            Applies the received color matrix to the current bitmap object

            This is very useful, and provides an easy and quick way to apply image transformations in just one step, without having to use the ImageAttributes class.

 

            Parameters:

                        toColorMatrix

 

            Returns: NULL

 

            See also: Special effects on images with GdiPlusX- Part1

                           Special effects on images with GdiPlusX – Part2

                           Draw Logos in your images with GdiPlusX - Part 2

                       

            Code sample:

 


DO LOCFILE("System.app")

WITH _Screen.System.Drawing 
   LOCAL loBmp as xfcBitmap
   loBmp = .
Bitmap.FromFile(GETPICT())
 
   LOCAL loClrMatrix as xfcColorMAtrix
   loClrMatrix = .Imaging.ColorMatrix.New(;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0, 0, 0, 1, 0, ;
      0, 0, 0, 0, 1) 
   loBmp.ApplyColorMatrix(loClrMatrix)
   loBmp.
Save("c:\ClrMatrix.Png", .Imaging.ImageFormat.Png)

ENDWITH

 

 

 

 

 

GetMask

 

           Returns a Bitmap object with the mask from the current bitmap

           In fact this function returns a bitmap with all the transparent parts of the image. Useful when you need to convert a PNG image that contains transparencies to be used in the BMP image format.

 

            Parameters: None

 

            Returns: Gdi+ bitmap object

 

            See also: Convert your buttons to BMPs keeping transparency with GdiPlusX

 

 

 

 

 

 

 

ToPrinter

 

            Sends the image object to the Printer

           

Parameters: tnStretch, tcPrinterName, tnOrientation, tnAlignment

                       

                        tnStretch

                        *   Specifies how an image is sized to fit inside a control.

                        *   0 - Clip. The image is clipped to fit the page. (Default)

                        *   1 - Isometric. The image resizes to fit the page while maintaining its original proportions.

                        *   2 - Stretch. The image resizes to fit the page, but does not maintain its original proportions.

                       

                        tcPrinterName

                        *   Specifies the name of the printer, the same of GETPRINTER()

                       

                        tnOrientation:

                        *   0 - Portrait

                        *   1 - Landscape

                       

                        tnAlignment

                        *   Specifies a numerical value representing the alignment of the image in the page.

                        *   0 - Vertically Centered Left.

                        *   1 - Vertically Centered Right.

                        *   2 - Centered. Centers image vertically and horizontally.

                        *   4 - Top Left. Aligns image in top left corner of the page.

                        *   5 - Top Right. Aligns image in top right corner of the page.

                        *   6 - Top Center. Aligns image at the top and horizontally centered on the page.

                        *   7 - Bottom Left. Aligns image in the bottom left corner of the page.

                        *   8 - Bottom Right. Aligns image in bottom right corner of the page.

                        *   9 - Bottom Center. Aligns image at the bottom and vertically centered on the page.

 

            Returns: Nothing

 

            Code sample:

 

 

DO LOCFILE("System.app")

 
WITH _Screen
.System.Drawing

   LOCAL
loBmp as xfcBitmap
   loBmp = .
Bitmap.FromFile(GETPICT
())
   loBmp.ToPrinter()
ENDWITH

 

 

 
 

 

 

xfcColorMatrix class

 

MatrixMultiply

 

            Returns a new Color Matrix object resulting of the multiplication of two color matrices. This is very useful when more than one color matrix is needed to be applied to an image. Multiplying the color matrices before they are applied to the image will bring a HUGE gain of performance.

 

            Parameters: toColorMatrixOne, ;

                        toColorMatrixTwo

                       

            Returns: a new color matrix containing the resultant matrix

 

            Code sample:

 

 

DO LOCFILE("System.app")


WITH _Screen
.System.Drawing


   LOCAL
loBmp as xfcBitmap
   loBmp = .
Bitmap.FromFile(GETPICT())

   LOCAL loClrMatrix1 as xfcColorMatrix && GreyScale matrix 
   loClrMatrix1 = .Imaging.ColorMatrix.New(;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0.33, 0.33, 0.33, 0, 0, ;
      0, 0, 0, 1, 0, ;
      0, 0, 0, 0, 1)

   LOCAL loClrMatrix2 as xfcColorMatrix && Half Brightness Matrix
   loClrMatrix2 = .Imaging.ColorMatrix.New(;
      0.5, 0, 0, 0, 0, ;
      0, 0.5, 0, 0, 0, ;
      0, 0, 0.5, 0, 0, ;
      0, 0, 0, 1, 0, ;
      0, 0, 0, 0, 1)

   LOCAL loNewClrMatrix as xfcColorMatrix
   loNewClrMatrix = loClrMatrix1.Multiply(loClrMatrix1, loClrMatrix2)

   loBmp.ApplyColorMatrix(loNewClrMatrix)
   loBmp.
Save("c:\MultClrMatrix.Png", .Imaging.ImageFormat.Png)

ENDWITH

 

 

 

 

 

xfcSize class

 

ToRectangle

            Returns a xfcRectangle object from the current xfcSizeF object

 

 

 

 

 

xfcSizef class

 

ToRectanglef

            Returns a xfcRectangleF object from the current xfcSizeF object

Published Monday, May 26, 2008 3:28 AM 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

 

Carlos Alloatti said:

Excellent article as always Cesar. Thank you very much. The only undocumented function I knew about was "GetMask" :)

Something you did not say in your post: GDIPLUSX is even better than the original NET classes, as it has less bugs, more functionality, and bugs are fixed instead of being converted into "features". :)

Hi Carlos,

Thanks for the kind words.

In fact, some of the functions that have been added to GdiPlusX have a great influence from you. Thanks for the valuable feedback and suggestions you've been providing !

Saludos !

May 27, 2008 2:20 AM

What do you think?

(required) 
(optional)
(required)