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



VFP-X GDI+ code samples for "Recreating One Note Tabs in VFP9" from Bernard

2007-Oct-23 - UPDATED, based on "BMPs with transparent backgrounds"

Now Bernard Bout is owing me 2 blog posts :-))

Below are some pictures from Bernard Bout, showing some very cool forms that he created. To ease his job, I'll show how to create on the fly the image files that he uses to create these examples, using the new classes from the GdiPlus-X project, available for download at CodePlex.

More information can be obtained in Bernard's blog post:"Recreating One Note Tabs in VFP9"

SAMPLE 1:  ON_BIGTAB

Target image enlarged 8 times :

Target image in original size :

** Creates an image ON_BIGTAB.PNG to be used in the "One Note Tabs"
** example from Bernard Bout
** - a 112x20 pixel image, with an irregular polygon with a blue
** border and filled with a gradient orange color
 
DO LOCFILE("System.App")

* Define the colors to be used
LOCAL lnRGBStartGradClr, lnRGBEndGradClr
lnRGBStartGradClr = RGB(253,233,218)   && light orange
lnRGBEndGradClr = RGB(247,182,131)     && orange
lnRGBBorderClr = RGB(59,97,156)        && dark blue

WITH _SCREEN.System.Drawing
 LOCAL loBitmap AS xfcBitmap
 LOCAL loGfx AS xfcGraphics
 LOCAL loGradBrush AS xfcLinearGradientBrush
 LOCAL loPen AS xfcPen
 LOCAL loRect AS xfcRectangle

 * Create a new 112x20 bitmap in the Default PixelFormat - 32bppARGB
 loBitmap = .Bitmap.New(112,20, 0, .Imaging.PixelFormat.Format24bppRGB)

 * Create a Graphics object to be able to draw in the bitmap
 loGfx = .Graphics.FromImage(loBitmap)
 loGfx.Clear(.Color.White) && white

 * Create a Rectangle for the linear gradient brush
 loRect = .Rectangle.New(0,0,112,19) && Size of bitmap
 
 * Create a Linear Gradient Brush
 loGradBrush = .Drawing2D.LinearGradientBrush.New(loRect,;
  .Color.FromRgb(lnRGBStartGradClr), .Color.FromRgb(lnRGBEndGradClr),1)

 DIMENSION laPoints(6)
 laPoints(1) = .Point.New(0,20)
 laPoints(2) = .Point.New(17,4)
 laPoints(3) = .Point.New(21,2)
 laPoints(4) = .Point.New(109,2)
 laPoints(5) = .Point.New(110,4)
 laPoints(6) = .Point.New(110,20)

 * Fill the polygon with Gradient Brush
 loGfx.FillPolygon(loGradBrush, @laPoints)
 
 * Create a blue Pen object to draw border
 loPen = .Pen.New(.Color.FromRGB(lnRGBBorderClr),1)

 * Draws the blue border
 laPoints(1) = .Point.New(0,19)
 laPoints(2) = .Point.New(17,2)
 laPoints(3) = .Point.New(22,0)
 laPoints(4) = .Point.New(109,0)
 laPoints(5) = .Point.New(111,2)
 laPoints(6) = .Point.New(111,18)

 loGfx.DrawLines(loPen, @laPoints)
 
 * Draw bottom-right pixels
 loBitmap.SetPixel(111,19,.Color.FromRGB(lnRGBEndGradClr))
 loBitmap.SetPixel(110,19,.Color.FromRGB(lnRGBEndGradClr))

 * Save the image
 loBitmap.Save("c:\ON_BigTab.png", .Imaging.ImageFormat.Png)
ENDWITH

 

 

SAMPLE 2: ON_SMALLTAB

Target image enlarged 8 times :

Target image in original size :

 

** Creates an image ON_SMALLTAB.PNG to be used in the "One Note Tabs"
** example from Bernard Bout
** - a 16x8 pixel image, with an irregular polygon with a blue border
** and filled with a gradient orange color

 
DO LOCFILE("System.App")

* Define the colors to be used
LOCAL lnRGBStartGradClr, lnRGBEndGradClr
lnRGBStartGradClr = RGB(255,232,197)  
&& light orange
lnRGBEndGradClr = RGB(255,179,15)    
  && orange
lnRGBBorderClr = RGB(26,57,86)         && dark blue

WITH _SCREEN.System.Drawing
 LOCAL loBitmap AS xfcBitmap
 LOCAL loGfx AS xfcGraphics
 LOCAL loGradBrush AS xfcLinearGradientBrush
 LOCAL loPen AS xfcPen
 LOCAL loRect AS xfcRectangle

 * Create a new 16x8 bitmap in the Default PixelFormat - 32bppARGB
 loBitmap = .Bitmap.New(16,8,0, .Imaging.PixelFormat.Format24bppRGB)

 * Create a Graphics object to be able to draw in the bitmap
 loGfx = .Graphics.FromImage(loBitmap)
 loGfx.Clear(.Color.FromRgb(RGB(255,255,255))) && white

 * Create a Rectangle for the linear gradient brush
 loRect = .Rectangle.New(0,0,16,8) && Size of bitmap
 
 * Create a Linear Gradient Brush
 loGradBrush = .Drawing2D.LinearGradientBrush.New(loRect,;
  .Color.FromRgb(lnRGBStartGradClr), .Color.FromRgb(lnRGBEndGradClr),1)

 DIMENSION laPoints(5)
 laPoints(1) = .Point.New(0,7)
 laPoints(2) = .Point.New(0,2)
 laPoints(3) = .Point.New(2,0)
 laPoints(4) = .Point.New(8,0)
 laPoints(5) = .Point.New(15,7)

 * Fill the polygon with Gradient Brush
 loGfx.FillPolygon(loGradBrush, @laPoints)

 * Create a blue Pen object to draw border
 loPen = .Pen.New(.Color.FromRGB(lnRGBBorderClr),1)

 * Draws the polygon
 loGfx.DrawPolygon(loPen, @laPoints)

 * Save the image
 loBitmap.Save("c:\ON_SmallTab.png", .Imaging.ImageFormat.Png)
ENDWITH

 

 

SAMPLE 3: ON_SMALLBUTTON

Original Image enlarged 8 times:                  Target image enlarged 8 times :

                                     

Original Image in normal size:                       Target image in original size :

                                                                          

 

** Loads an image and draws a customized rectangle using a
** LinearGradientBrush; Creates image file ON_SMALLBUTTON.PNG
** to be used in the "One Note Tabs" example from Bernard Bout
** - a 112x20 pixel image, with an irregular polygon with a blue
** border and filled with a gradient orange color
 
DO LOCFILE("System.App")

* Define the colors to be used
LOCAL lnRGBStartGradClr, lnRGBEndGradClr
lnRGBStartGradClr = RGB(253,232,197)   && light orange
lnRGBEndGradClr = RGB(255,179,15)      && orange

WITH _SCREEN.System.Drawing
 LOCAL loBitmap AS xfcBitmap
 LOCAL loGfx AS xfcGraphics
 LOCAL loGradBrush AS xfcLinearGradientBrush
 LOCAL loRect AS xfcRectangle

 * Load the Image file
 loBitmap = .Image.FromFile(GETPICT())

 * Create a Graphics object to be able to draw in the bitmap
 loGfx = .Graphics.FromImage(loBitmap)

 * Create a Rectangle for the linear gradient brush
 loRect = .Rectangle.New(0,0,12,18)
 
 * Create a Linear Gradient Brush
 loGradBrush = .Drawing2D.LinearGradientBrush.New(loRect,;
  .Color.FromRgb(lnRGBStartGradClr), .Color.FromRgb(lnRGBEndGradClr),1)

 * Fill the polygon with Gradient Brush
 loGfx.FillRectangle(loGradBrush, 3, 1, 12, 17)

 * Save the image
 loBitmap.Save("c:\ON_SmallButton.png", .Imaging.ImageFormat.Png)
ENDWITH

 

Again, Let's wait for Bernard's next appearances !

Published Sunday, August 13, 2006 7:17 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

 

Ana María Bisbé said:

Versión en Español de este artículo en / Spanish version at http://www.portalfox.com/article.php?sid=2259
July 24, 2007 7:06 PM
 

Cesar Chalom said:

Here are some notes on BMP transparencies on VFP, based in some conclusions I took after some discussions...
October 24, 2007 1:17 PM

What do you think?

(required) 
(optional)
(required)