Drawings with gdiplusX -part I

Published on by Yousfi Benameur

Five codes are presented below to show drawings in gdiplusX.

Can select any code and copy it to a prg

Always have the latest stable system.app version (download in vfpX codeplex).

As prg the code must also to point to gdiplusX.vcx

 

gdiplusX proj download at codeplex (system app included) :

http://vfpx.codeplex.com/wikipage?title=gdiplusx&referringtitle=home

 

 

*This demo code makes some drawings with gdiplusX on imgcanvas control.
*it overlaps points,paths,drawing2, arrays colors..,
*pens, xfcGradientBrushes,surroundcolors,centercolors,...
*it draws, fills rectangles,triangle, ellipse,roundRectangles,..
*it draws text with fonts,style,...
*-Can capture the imgcanvas contents and show in Mspaint (resize,can save as...)
*-Can save directly with the ( image format+width+height ) set to an image (in "images" folder created)

*Begin code
Publi m.yrep
m.yrep=Addbs(Justpath(Sys(16,1))) && for a form : Sys(1271,This)))
If !Directory(m.yrep+"images")
Md (m.yrep+"images")
Endi

do locfile("system.app") &&point to system.app
Set Classlib To Locfile("gdiplusX") AddI &&point mandatory to gdiplusX class location


Publi yform
yform=Newobject("ydrawings")
Release Classlib "gdiplusX"
yform.Show
Read Events
*

Define Class ydrawings As Form
BorderStyle = 3
Height = 718
Width = 1010
ShowWindow = 2
AutoCenter = .T.
Caption = "gdiPlusX samples"
BackColor = Rgb(0,0,0)
ycolor1 = 255
ycolor2 = 1245
nmode = 3
Name = "Form1"

Add Object imgcanvas1 As imgcanvas With ;
Anchor = 15, ;
Stretch = 2, ;
Height = 648, ;
Left = 0, ;
Top = 0, ;
Width = 1020, ;
Name = "Imgcanvas1"

Add Object command1 As CommandButton With ;
Top = 673, ;
Left = 408, ;
Height = 39, ;
Width = 108, ;
FontBold = .T., ;
FontSize = 10, ;
Anchor = 768, ;
Caption = "Switch colors", ;
MousePointer = 15, ;
ForeColor = Rgb(255,0,0), ;
BackColor = Rgb(0,255,0), ;
Name = "Command1"

Add Object yb8 As CommandButton With ;
Top = 673, ;
Left = 530, ;
Height = 39, ;
Width = 61, ;
Anchor = 768, ;
Picture = "", ;
Caption = "", ;
MousePointer = 15, ;
ToolTipText = "Capture image+View", ;
BackColor = Rgb(128,0,255), ;
Name = "yb8"

Add Object command2 As CommandButton With ;
Top = 672, ;
Left = 852, ;
Height = 39, ;
Width = 121, ;
FontBold = .T., ;
FontSize = 10, ;
Anchor = 768, ;
Picture = "d:\yvfp\ysvg\apphoto.bmp", ;
Caption = "Save as ..", ;
MousePointer = 15, ;
ToolTipText = "Capture image+View", ;
ForeColor = Rgb(255,0,0), ;
BackColor = Rgb(128,0,255), ;
Name = "Command2"

Add Object combo1 As ComboBox With ;
Anchor = 768, ;
Height = 25, ;
Left = 660, ;
Top = 684, ;
Width = 61, ;
Name = "Combo1"

Add Object text1 As TextBox With ;
Anchor = 768, ;
Alignment = 3, ;
Value = 800, ;
Height = 25, ;
Left = 732, ;
ToolTipText = "Width", ;
Top = 684, ;
Width = 49, ;
Name = "Text1"

Add Object text2 As TextBox With ;
Anchor = 768, ;
Alignment = 3, ;
Value = 600, ;
Height = 25, ;
Left = 789, ;
ToolTipText = "Height", ;
Top = 683, ;
Width = 49, ;
Name = "Text2"

Procedure getpath
Lparameters rc,r
Local x,Y,xwidth,xheight,xpath

Local g As Graphics
Local p As Pen
x = rc.x
Y = rc.Y
xwidth = rc.Width
xheight = rc.Height
With _Screen.System.Drawing
xpath = .Drawing2D.GraphicsPath.New()
xpath.AddArc(x, Y, r, r, 180, 90) && Upper left corner
xpath.AddArc(x+xwidth - r, Y, r, r, 270, 90) && Upper right corner
xpath.AddArc(x+xwidth - r, Y+xheight - r, r, r, 0, 90) && Lower right corner
xpath.AddArc(x, Y+xheight - r, r, r, 90, 90) && Lower left corner
xpath.CloseFigure()
Endwith
Return xpath
Endproc

Procedure yrandom
nRed1=Int(255*Rand() )
nGreen1=Int(255*Rand() )
nBlue1=Int(255*Rand() )

nRed2=Int(255*Rand() )
nGreen2=Int(255*Rand() )
nBlue2 =Int(255*Rand() )
Thisform.ycolor1=Rgb(nRed1,nGreen1,nBlue1)
Thisform.ycolor2=Rgb(nRed2,nGreen2,nBlue2)
Endproc

Procedure Init
Publi m.ii
m.ii=0
With Thisform
.Caption="GdiPlusX Drawings"
.MaxButton=.F.
.BorderStyle=2
.imgcanvas1.Left=This.Left
.imgcanvas1.Top=This.Top
.imgcanvas1.Width=This.Width
.imgcanvas1.Height=This.Height-This.command1.Top
.imgcanvas1.Anchor=15
.ycolor1=Rgb(255,0,0)
.ycolor2=Rgb(0,255,0)
.AddObject("yhelp1","yhelp")
.yhelp1.Visible=.T.
Endwith
Endproc

Procedure imgcanvas1.beforedraw
logfx=This.ogfx
With _Screen.System.Drawing
logfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias
This.Clear(.Color.black)

Local yPath As xfcGraphicsPath
w=This.rectangle.Width-20
h=This.rectangle.Height-20

point1=.Point.New(10,10)
point2=.Point.New(10,h/2)
point3=.Point.New(w/3,h/2)
point4=.Point.New(w/3,10)

yPath = .Drawing2D.GraphicsPath.New()
yPath.AddLine(point1,point2)
yPath.AddLine(point2,point3)
yPath.AddLine(point3,point4)
yPath.AddLine(point4,point1)
yPath.CloseFigure()

*draw rectangle
Pen = .Pen.New(.Color.gold, 6)
logfx.DrawPath(Pen,yPath)

Local pgb As xfcPathGradientBrush
pgb=.Drawing2D.PathGradientBrush.New(yPath)
Dimension acolor(5)
*colorArray= .color.new(.color.red,.color.green,.color.blue)
acolor(1)=.Color.red
acolor(2)=.Color.green
acolor(3)=.Color.blue
acolor(4)=.Color.yellow
acolor5=.Color.violet
For i=1 To 5
pgb.SurroundColors[i]=acolor(i)
Endfor
pgb.CenterColor=.Color.fromRGB(Thisform.ycolor2)
logfx.FillPath(pgb,yPath)
pgb.Dispose()

*triangle
Local yPath As xfcGraphicsPath
w=This.rectangle.Width-20
h=This.rectangle.Height-20

point1=.Point.New(450+78,10)
point2=.Point.New(450+78-0.58*h/2,h/2)
point3=.Point.New(0.58*h/2+450+78,h/2)

yPath = .Drawing2D.GraphicsPath.New()
yPath.AddLine(point1,point2)
yPath.AddLine(point2,point3)
yPath.AddLine(point3,point1)
yPath.CloseFigure()

*draw rectangle
Pen = .Pen.New(.Color.gold, 6)
logfx.DrawPath(Pen,yPath)

Local pgb As xfcPathGradientBrush
pgb=.Drawing2D.PathGradientBrush.New(yPath)
Dimension acolor(3)
acolor(1)=.Color.cyan
acolor(2)=.Color.red
acolor(3)=.Color.yellow
*pgb.SurroundColors = .color.new(.Color.red,.color.green,.color.yellow,.color.blue)
For i=1 To 3
pgb.SurroundColors(i)=acolor(i)
Endfor

pgb.CenterColor=(.Color.fromRGB(Thisform.ycolor2)) &&.Color.gold &&gray
logfx.FillPath(pgb,yPath)
pgb.Dispose()

&&ellipse
w=This.rectangle.Width-20
h=This.rectangle.Height-20
yPath = .Drawing2D.GraphicsPath.New()
yPath.addellipse(560+90,10,0.35*w,0.47*h)
*draw ellipse
Pen = .Pen.New(.Color.gold, 6)
logfx.DrawPath(Pen,yPath)

pgb=.Drawing2D.PathGradientBrush.New(yPath,3)
pgb.CenterColor=.Color.fromRGB(Thisform.ycolor1)
ybl=.Drawing2D.Blend.New()
ybl.Factors =_Screen.System.Single.newArray(1,0,1,0,1)
ybl.Positions=_Screen.System.Single.newArray(0,0.4,0.6,0.8,1)
pgb.Blend=ybl

logfx.fillRectangle(pgb,This.rectangle)
pgb.Dispose()

&&roundRectangle
rc = .rectangle.New(10,300+40,This.Width/3, This.Height/3)
r=30
yPath = Thisform.getpath(rc, r)
*draw the roundrectangle
tncolor=.Color.fromRGB(Thisform.ycolor1)
Pen = .Pen.New(tncolor, 6)
logfx.DrawPath(Pen,yPath)

pgb=.Drawing2D.PathGradientBrush.New(yPath)
pgb.CenterColor=.Color.fromRGB(Thisform.ycolor1)
ybl=.Drawing2D.Blend.New()
ybl.Factors =_Screen.System.Single.newArray(1,0,1,0,10,1)
ybl.Positions=_Screen.System.Single.newArray(0,0.2,0.5,0.6,0.7,1)
pgb.Blend=ybl
logfx.FillPath(pgb,yPath)
pgb.Dispose()

&&ellipse
w=This.rectangle.Width-20
h=This.rectangle.Height-20
yPath = .Drawing2D.GraphicsPath.New()
yPath.addellipse(320+40,290+40,0.35*w,0.4*h)
*draw ellipse
Pen = .Pen.New(.Color.gold, 6)
logfx.DrawPath(Pen,yPath)

pgb=.Drawing2D.PathGradientBrush.New(yPath,3)
pgb.CenterColor=.Color.fromRGB(Thisform.ycolor1)
ybl=.Drawing2D.Blend.New()
ybl.Factors =_Screen.System.Single.newArray(1,0,1,0,1,0,1,0,1)
ybl.Positions=_Screen.System.Single.newArray(0,0.1,0.2,0.3,0.5,0.6,0.7,0.9,1)
pgb.Blend=ybl
logfx.fillRectangle(pgb,This.rectangle)
pgb.Dispose()

w=This.rectangle.Width-20
h=This.rectangle.Height-20
point1=.Point.New(660+70,290+40)
point2=.Point.New(670+60,290+40+0.35*h)
point3=.Point.New(660+70+250,290+40+0.35*h)
point4=.Point.New(660+70+250,290+40)

yPath = .Drawing2D.GraphicsPath.New()
yPath.AddLine(point1,point2)
yPath.AddLine(point2,point3)
yPath.AddLine(point3,point4)
yPath.AddLine(point4,point1)
yPath.CloseFigure()

*draw rectangle
Pen = .Pen.New(.Color.gold, 6)
logfx.DrawPath(Pen,yPath)

pgb=.Drawing2D.PathGradientBrush.New(yPath)
pgb.CenterColor=.Color.fromRGB(Thisform.ycolor1)

ybl=.Drawing2D.Blend.New()
ybl.Factors =_Screen.System.Single.newArray(1,0,1,0,1,0)
ybl.Positions=_Screen.System.Single.newArray(0,0.2,0.4,0.6,0.8,1)
pgb.Blend=ybl

logfx.FillPath(pgb,yPath)
pgb.Dispose()

*texte
Local loFont As xfcFont
Local loBrush As xfcLinearGradientBrush
Local loRectangleF As xfcRectangleF
Local loSizeF As xfcSizeF

ystring="GdiPlusX sous Visual Foxpro 9"
loFont = .Font.New("Arial Black", 14, .FontStyle.BoldItalic)
loSizeF = logfx.MeasureString(ystring, loFont)
loRectangleF =_Screen.System.Drawing.RectangleF.New((This.Width-loSizeF.Width-10)/2,This.Height-loSizeF.Height-5,loSizeF.Width, loSizeF.Height)
loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,.Color.red,.Color.green,3)
logfx.DrawString(ystring, loFont,loBrush, loRectangleF)

ystring="Yousfi Benameur November,2008"
loFont = .Font.New("tahoma", 9, .FontStyle.BoldItalic)
loSizeF = logfx.MeasureString(ystring, loFont)
loRectangleF =_Screen.System.Drawing.RectangleF.New(This.Width-loSizeF.Width-10,This.Height-loSizeF.Height-5,loSizeF.Width, loSizeF.Height)
loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,.Color.red,.Color.green,3)
logfx.DrawString(ystring, loFont,loBrush, loRectangleF)

Endwith
Return

Endproc


Procedure command1.Click
&&get a random color
Thisform.yrandom()

Thisform.nmode=Thisform.nmode+1
If Thisform.nmode>3
Thisform.nmode=1
Endi
Thisform.imgcanvas1.Draw()
Endproc

Procedure yb8.Init
This.Picture=Home(1)+"graphics\icons\misc\camera.ico"
Endproc

Procedure yb8.Click
Thisform.imgcanvas1.oBmp.toClipboard()
Run/n3 mspaint
Inkey(2)
loShell=Createobject("wscript.shell")
loShell.sendKeys("^{v}")
Endproc

Procedure command2.Click
Local m.x,lnWidth,lnHeight
m.x=Ttoc(Datetime())
m.x=Strtran(m.x,'/','_')
m.x=Strtran(m.x,';','_')
m.x=Strtran(m.x,":","_")
m.x=m.yrep+"images\"+"ycap_"+m.x+"."+Thisform.combo1.Value

Local loResized As xfcBitmap
With _Screen.System.Drawing
m.lnWidth=Thisform.text1.Value
m.lnHeight=Thisform.text2.Value
loResized = .Bitmap.New(Thisform.imgcanvas1.oBmp,m.lnWidth, m.lnHeight)
loResized.Save(m.x,Eval(".imaging.imageformat."+Thisform.combo1.Value))
Messagebox(m.x+" saved",0x1000,"",500)
Endwith
Endproc

Procedure combo1.Init
With This
.AddItem("PNG")
.AddItem("JPEG")
.AddItem("BMP")
.AddItem("GIF")
.Style=2
.ListIndex=1
Endwith
Endproc
Procedure Destroy
Clea Events
Endproc

Enddefine
*
Define Class yhelp As Label
AutoSize = .T.
FontBold = .T.
FontSize = 22
BackStyle = 0
Caption = "?"
Height = 37
Left = 360
MousePointer = 15
Top = 672
Width = 20
ForeColor = Rgb(0,255,0)
ToolTipText = "Summary help"
Name = "Label1"

Procedure Click
Local m.myvar
TEXT to m.myvar noshow
This demo code makes some drawings with gdiplusX on imagcanvas control.
it overlaps points,paths,drawing2D,
pens, xfcGradientBrushes,surroundcolors,centercolors,...
it draws, fills rectangles,triangle, ellipse,roundRectangles,..
it draws text with fonts,style,...
-Can capture the imgcanvas contents and show in Mspaint(can save as...)
-Can save directly with ths image format+width+height set to an image (in "images" folder created)
ENDTEXT
Messagebox(m.myvar,0+32+4096,"GdiplusX")
Endproc
Enddefine

*End Code

The image of the executed code (form) and some screenshots.
The image of the executed code (form) and some screenshots.
The image of the executed code (form) and some screenshots.
The image of the executed code (form) and some screenshots.

The image of the executed code (form) and some screenshots.

*This code draws a triangle with surrounders colors and centercolor.
*System.app must be latest release to make this code working.
*Point also to gdiplusX class.
*Can capture contents to mspaint (viex, resize, save as..)
*Can save directly to png,jpg,bmp,gif with the set dimensions(captures
*are located in image folder cretaed).
*        *November 2008

*Begin code
Publi m.yrep
m.yrep=Addbs(Justpath(Sys(16,1)))   && for a form : Sys(1271,This)))
If !Directory(m.yrep+"images")
    Md (m.yrep+"images")
Endi

do locfile("system.app") &&point to system.app
Set Classlib To Locfile("gdiplusX") AddI  &&point mandatory to gdiplusX class location

publi yform
yform=newObject("ytriangle")
release classlib "gdiplusX"
yform.show
read events
return

*
DEFINE CLASS ytriangle AS form
    Height = 624
    Width = 864
    ShowWindow = 2
    ShowTips = .T.
    AutoCenter = .T.
    Caption = "GdiplusX samples  triangle gradients "
    KeyPreview = .T.
    BackColor = RGB(0,0,0)
    ycolor1 = ""
    ycolor2 = ""
    nmode = 3
    ycount = 0
    Name = "Form1"

    ADD OBJECT imgcanvas1 AS imgcanvas WITH ;
        Anchor = 15, ;
        Stretch = 2, ;
        Height = 564, ;
        Left = 0, ;
        Top = 0, ;
        Width = 864, ;
        Name = "Imgcanvas1"

    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 575, ;
        Left = 304, ;
        Height = 40, ;
        Width = 84, ;
        FontBold = .T., ;
        Anchor = 768, ;
        Caption = "Swith colors", ;
        BackColor = RGB(0,255,0), ;
        Name = "Command1"

    ADD OBJECT timer1 AS timer WITH ;
        Top = 576, ;
        Left = 120, ;
        Height = 23, ;
        Width = 23, ;
        Enabled = .F., ;
        Interval = 250, ;
        Name = "Timer1"

    ADD OBJECT command2 AS commandbutton WITH ;
        Top = 578, ;
        Left = 36, ;
        Height = 27, ;
        Width = 84, ;
        FontBold = .T., ;
        Anchor = 768, ;
        Caption = "Effects", ;
        Enabled = .T., ;
        ToolTipText = "ESC to stop playing", ;
        Name = "Command2"

    ADD OBJECT yb8 AS commandbutton WITH ;
        Top = 575, ;
        Left = 432, ;
        Height = 41, ;
        Width = 44, ;
        Anchor = 768, ;
        Caption = "", ;
        ToolTipText = "Capture  image+View", ;
        BackColor = RGB(128,128,255), ;
        Name = "yb8"

    ADD OBJECT command3 AS commandbutton WITH ;
        Top = 579, ;
        Left = 733, ;
        Height = 39, ;
        Width = 121, ;
        FontBold = .T., ;
        FontSize = 10, ;
        Anchor = 768, ;
        Picture = "d:\yvfp\ysvg\apphoto.bmp", ;
        Caption = "Save as ...", ;
        MousePointer = 15, ;
        ToolTipText = "Capture  image+View", ;
        ForeColor = RGB(255,0,0), ;
        BackColor = RGB(128,0,255), ;
        Name = "Command3"

    ADD OBJECT combo1 AS combobox WITH ;
        Anchor = 768, ;
        Height = 25, ;
        Left = 541, ;
        Top = 591, ;
        Width = 61, ;
        Name = "Combo1"

    ADD OBJECT text1 AS textbox WITH ;
        Anchor = 768, ;
        Alignment = 3, ;
        Value = 800, ;
        Height = 25, ;
        Left = 613, ;
        ToolTipText = "Width", ;
        Top = 591, ;
        Width = 49, ;
        Name = "Text1"

    ADD OBJECT text2 AS textbox WITH ;
        Anchor = 768, ;
        Alignment = 3, ;
        Value = 600, ;
        Height = 25, ;
        Left = 670, ;
        ToolTipText = "Height", ;
        Top = 590, ;
        Width = 49, ;
        Name = "Text2"

    ADD OBJECT label1 AS label WITH ;
        AutoSize = .T., ;
        FontBold = .T., ;
        FontSize = 22, ;
        BackStyle = 0, ;
        Caption = "?", ;
        Height = 37, ;
        Left = 241, ;
        Anchor=768, ;
        MousePointer = 15, ;
        Top = 579, ;
        Width = 20, ;
        ForeColor = RGB(0,255,0), ;
        ToolTipText = "Summary help", ;
        Name = "Label1"

    PROCEDURE getpath
        LPARAMETERS rc,r
        LOCAL x,y,xwidth,xheight,xpath

        local g As Graphics
          local p As Pen
        x = rc.X
        y = rc.Y
        xwidth   = rc.Width
        xheight = rc.Height
        WITH _screen.system.Drawing
            xpath = .Drawing2D.GraphicsPath.New()
            xpath.AddArc(x, y, r, r, 180, 90)            && Upper left corner
            xpath.AddArc(x+xwidth - r, y, r, r, 270, 90)        &&  Upper right corner
            xpath.AddArc(x+xwidth - r, y+xheight - r, r, r, 0, 90)    &&  Lower right corner
            xpath.AddArc(x, y+xheight - r, r, r, 90, 90)        &&  Lower left corner
            xpath.CloseFigure()
        ENDWITH
        return xpath

    ENDPROC

    PROCEDURE KeyPress
        LPARAMETERS nKeyCode, nShiftAltCtrl
        if nkeycode=27
        this.timer1.enabled=.f.
        endi
    ENDPROC

    PROCEDURE Init
        publi m.ii,m.yrep
        m.yrep=addbs(justpath(sys(16,1)))       &&sys(1271,this))) && for a form
        if !directory(m.yrep+"images")
        md (m.yrep+"images")
        endi

        thisform.setall("mousepointer",15,"commandbutton")
        publi ii
        ii=0
        this.imgcanvas1.left=this.left
        this.imgcanvas1.top=this.top
        this.imgcanvas1.width=this.width
        this.imgcanvas1.height=this.height-this.command1.top
        this.ycolor1=".color.red"
    ENDPROC

    PROCEDURE Unload
        for i=1 to _screen.formcount
        if lower(_screen.forms(i).name)="ymain"
        ymain.windowstate=0
        endi
        endfor
    ENDPROC

    PROCEDURE imgcanvas1.beforedraw

        This.Clear()

        logfx=this.ogfx
         WITH _screen.system.Drawing
         loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias
        this.clear(.color.black)


        Local yPath As xfcGraphicsPath
        point1=.point.new(0.87*this. Rectangle.Width/2,10)
        point2=.point.new(10,this. Rectangle.Height-20)
        point3=.point.new(this. Rectangle.Width,this. Rectangle.Height-20)

        ypath = .Drawing2D.GraphicsPath.New()
        ypath.addline(point1,point2)
        ypath.addline(point2,point3)
        ypath.addline(point3,point1)
        ypath.CloseFigure()

        PEN = .PEN.NEW(.color.gold, 6)
        loGfx.DrawPath(PEN,ypath)

          Local pgb As xfcPathGradientBrush
          pgb=.Drawing2d.PathGradientBrush.new(ypath)
        *colorArray= .color.new(.color.red,.color.green,.color.blue)
        *pgb.SurroundColors[1]=colorArray
        *pgb.SurroundColors = .color.new(.color.red,.color.green,.color.yellow)

        dimension colorArray(3)
        colorArray[1]=.color.red  
        colorArray[2]=.color.green
        colorArray[3]=.color.blue
        for i=1 to 3
        pgb.SurroundColors[i]=colorArray[i]
        endfor

            pgb.CenterColor=evaluate(thisform.ycolor1)    &&.color.cyan
            loGfx.FillPath(pgb,ypath)     
            pgb.Dispose()
        
        &&soleil
        Local loPath As xfcGraphicsPath
        loPath = .Drawing2D.GraphicsPath.New()
        loPath.AddEllipse(THIS.left+20,this.top+60, 80, 80)
        Local loPathGradBrush As xfcPathGradientBrush
        loPathGradBrush = .Drawing2D.PathGradientBrush.New(loPath)
        loPathGradBrush.SurroundColors[1] =.color.yellow    && .color.new(.Color.red,.color.green,.color.blue)

        loPathGradBrush.CenterColor =evaluate(thisform.ycolor1)
        loGfx.FillEllipse(loPathGradBrush, this.left+20,this.top+ 60, 80, 80)

        *texte
        LOCAL loFont AS xfcFont
        LOCAL loBrush AS xfcLinearGradientBrush
        LOCAL loRectangleF As xfcRectangleF
        LOCAL loSizeF AS xfcSizeF

        ystring="GdiPlusX sous Visual Foxpro 9"
           loFont = .Font.New("Arial Black", 14,  .FontStyle.BoldItalic)
            loSizeF = loGfx.MeasureString(ystring, loFont)
            loRectangleF =_screen.system.Drawing.RectangleF.New(0,0,loSizeF.Width, loSizeF.Height)
            loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,.Color.red,.Color.green,3)
            loGfx.DrawString(ystring, loFont,loBrush, loRectangleF)

        ystring="Yousfi Benameur November,2008"
           loFont = .Font.New("tahoma", 9,  .FontStyle.BoldItalic)
            loSizeF = loGfx.MeasureString(ystring, loFont)
            loRectangleF =_screen.system.Drawing.RectangleF.New(this.width-loSizeF.width-10,this.height-loSizeF.height,loSizeF.Width, loSizeF.Height)
            loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,.Color.red,.Color.green,3)
            loGfx.DrawString(ystring, loFont,loBrush, loRectangleF)

            endwith
        return

    ENDPROC


    PROCEDURE command1.Click
        &&random color
                nRed1=INT(255*rand())
                nGreen1=INT(255*rand())  
                nBlue1=INT(255*rand())  

                nRed2=INT(255*rand())  
                nGreen2=INT(255*rand())
                nBlue2 =INT(255*rand())  
        thisform.ycolor1=rgb(nred1,ngreen1,nblue1)
        thisform.ycolor2=rgb(nred2,ngreen2,nblue2)
        thisform.nmode=thisform.nmode+1

        if thisform.nmode>3
        thisform.nmode=1
        endi

        ii=ii+1
        if ii>10
        ii=1
        endi

        do case
        case ii=1
        thisform.ycolor1=".color.red"
        case ii=2
        thisform.ycolor1=".color.green"
        case ii=3
        thisform.ycolor1=".color.blue"
        case ii=4
        thisform.ycolor1=".color.cyan"
        case ii=5
        thisform.ycolor1=".color.yellow"
        case ii=6
        thisform.ycolor1=".color.magenta"
        case ii=7
        thisform.ycolor1=".color.gold"
        case ii=8
        thisform.ycolor1=".color.gray"
        case ii=9
        thisform.ycolor1=".color.black"
        case ii=10
        thisform.ycolor1=".color.purple"
        endcase

        thisform.imgcanvas1.draw()
    ENDPROC


    PROCEDURE timer1.Timer
        thisform.ycount=thisform.ycount+1
        if thisform.ycount<=10
        thisform.command1.click
        else
        thisform.ycount=0
        this.enabled=.f.
        endi
    ENDPROC

    PROCEDURE command2.Click
        thisform.timer1.enabled=.t.
    ENDPROC

    PROCEDURE yb8.Init
        this.picture=home(1)+"graphics\icons\misc\camera.ico"
    ENDPROC

    PROCEDURE yb8.Click
        LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder
        lnTitleHeight = SYSMETRIC(9)
        lnLeftBorder = SYSMETRIC(3)
        lnTopBorder = SYSMETRIC(4)

        LOCAL loCaptureBmp as xfcBitmap
        loCaptureBmp = _screen.system.Drawing.Bitmap.FromScreen(Thisform.HWnd, ;
            lnLeftBorder, lnTitleHeight + lnTopBorder, ;
              Thisform.Width, ;
              Thisform.imgcanvas1.Height)

        loCaptureBmp.toClipboard()
        run/n3 mspaint
        inkey(2)
        loShell=createObject("wscript.shell")
        loShell.sendKeys("^{v}")
    ENDPROC

    PROCEDURE command3.Click
        Local m.x,lnWidth,lnHeight
        m.x=Ttoc(Datetime())
        m.x=Strtran(m.x,'/','_')
        m.x=Strtran(m.x,';','_')
        m.x=Strtran(m.x,":","_")
        m.x=m.yrep+"images\"+"ycap_"+m.x+"."+Thisform.combo1.Value

        Local loResized As xfcBitmap

        With _Screen.System.Drawing
            m.lnWidth=Thisform.text1.Value
            m.lnHeight=Thisform.text2.Value
            loResized = .Bitmap.New(Thisform.imgcanvas1.oBMp,m.lnWidth, m.lnHeight)
            loResized.Save(m.x,Eval(".imaging.imageformat."+Thisform.combo1.Value))
            Messagebox(m.x+" saved",0x1000,"",500)
        Endwith
    ENDPROC

    PROCEDURE combo1.Init
        with this
        .additem("PNG")
        .additem("JPEG")
        .additem("BMP")
        .additem("GIF")
        .style=2
        .listindex=1
        endwith
    ENDPROC

    PROCEDURE label1.Click
        local m.myvar
        text to m.myvar noshow
        This code draws a triangle with surrounders colors and centercolor.
System.app must be latest release to make this code working.
Point also to gdiplusX class.
Can capture contents to mspaint (viex, resize, save as..)
Can save directly to png,jpg,bmp,gif with the set dimensions(captures
are located in image folder cretaed).
    *November 2008
        endtext
        messagebox(m.myvar,0+32+4096,"GdiplusX")
    ENDPROC
    
    PROCEDURE DESTROY
    CLEA EVENTS
    ENDPROC

ENDDEFINE
*

*END code

If you have not these colors your system.app is not updated (download latest in codeplex)
If you have not these colors your system.app is not updated (download latest in codeplex)
If you have not these colors your system.app is not updated (download latest in codeplex)
If you have not these colors your system.app is not updated (download latest in codeplex)

If you have not these colors your system.app is not updated (download latest in codeplex)

*This demo code makes some drawings with gdiplusX on imagcanvas control.
*it overlaps points,paths,drawing2D,
*pens, xfcGradientBrushes,surroundcolors,centercolors,...
*it draws, fills areas...
*it draws text with fonts,style,...
*-Can capture the imgcanvas contents and show in Mspaint(can save as...)
*-Can save directly with ths image format+width+height set to an image (in "images"
* folder created)

*Begin code
Publi m.yrep
m.yrep=Addbs(Justpath(Sys(16,1)))   && for a form : Sys(1271,This)))
If !Directory(m.yrep+"images")
    Md (m.yrep+"images")
Endi

Do Locfile("system.app") &&point to system.app
Set Classlib To Locfile("gdipludX") AddI  &&point mandatory to gdiplusX class location
Publi yform
yform=Newobject("ygrad")
Release Classlib "gdiplusX"
yform.Show
Read Events
*

Define Class ygrad As Form
    Height = 613
    Width = 864
    ShowWindow = 2
    ShowTips = .T.
    AutoCenter = .T.
    Caption = "gdiPlusX samples"
    ycolor1 = 255
    ycolor2 = 65266
    nmode = 3
    cas = 1
    Name = "Form1"

    Add Object imgcanvas1 As imgcanvas With ;
        Anchor = 15, ;
        Stretch = 2, ;
        Height = 552, ;
        Left = 0, ;
        Top = 0, ;
        Width = 864, ;
        Name = "Imgcanvas1"

    Add Object yb2 As CommandButton With ;
        Top = 575, ;
        Left = 101, ;
        Height = 27, ;
        Width = 115, ;
        Caption = "Linear grad/Blend", ;
        ToolTipText = "Clic many times  to swith colors", ;
        Name = "yb2"

    Add Object yb3 As CommandButton With ;
        Top = 576, ;
        Left = 218, ;
        Height = 27, ;
        Width = 120, ;
        Caption = "Non linear Gradient", ;
        ToolTipText = "Clic many times  to swith colors", ;
        Name = "yb3"

    Add Object yb4 As CommandButton With ;
        Top = 575, ;
        Left = 341, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "9 colors grad", ;
        Name = "yb4"

    Add Object yb5 As CommandButton With ;
        Top = 574, ;
        Left = 422, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Blends", ;
        Name = "yb5"

    Add Object yb6 As CommandButton With ;
        Top = 574, ;
        Left = 506, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Path grad", ;
        ToolTipText = "Clic many times  to swith colors", ;
        Name = "yb6"

    Add Object yb1 As CommandButton With ;
        Top = 576, ;
        Left = 3, ;
        Height = 27, ;
        Width = 96, ;
        Caption = "Linear gradients", ;
        ToolTipText = "Clic many times to swith colors", ;
        Name = "yb1"

    Add Object yb7 As CommandButton With ;
        Top = 575, ;
        Left = 595, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Triangle grad", ;
        ToolTipText = "Clic many times to swith colors", ;
        Name = "yb7"

    Add Object yb8 As CommandButton With ;
        Top = 569, ;
        Left = 720, ;
        Height = 39, ;
        Width = 61, ;
        Anchor = 768, ;
        Picture = "d:\yvfp\ysvg\apphoto.bmp", ;
        Caption = "", ;
        MousePointer = 15, ;
        ToolTipText = "Capture  image+View", ;
        BackColor = Rgb(128,0,255), ;
        Name = "yb8"

    Add Object label1 As Label With ;
        AutoSize = .T., ;
        FontBold = .T., ;
        FontSize = 22, ;
        BackStyle = 0, ;
        Caption = "?", ;
        Height = 37, ;
        Left = 694, ;
        aNCHOR=768, ;
        MousePointer = 15, ;
        Top = 571, ;
        Width = 20, ;
        ForeColor = Rgb(0,255,0), ;
        ToolTipText = "Summary help", ;
        Name = "Label1"

    Procedure getpath
        Lparameters rc,r
        Local x,Y,xwidth,xheight,xpath

        Local g As Graphics
        Local p As Pen
        x = rc.x
        Y = rc.Y
        xwidth   = rc.Width
        xheight = rc.Height
        With _Screen.System.Drawing
            xpath = .Drawing2D.GraphicsPath.New()
            xpath.AddArc(x, Y, r, r, 180, 90)            && Upper left corner
            xpath.AddArc(x+xwidth - r, Y, r, r, 270, 90)        &&  Upper right corner
            xpath.AddArc(x+xwidth - r, Y+xheight - r, r, r, 0, 90)    &&  Lower right corner
            xpath.AddArc(x, Y+xheight - r, r, r, 90, 90)        &&  Lower left corner
            xpath.CloseFigure()
        Endwith
        Return xpath
    Endproc

    Procedure yrandom
        nRed1=Int(255*Rand() )
        nGreen1=Int(255*Rand() )
        nBlue1=Int(255*Rand() )

        nRed2=Int(255*Rand() )
        nGreen2=Int(255*Rand() )
        nBlue2 =Int(255*Rand() )
        Thisform.ycolor1=Rgb(nRed1,nGreen1,nBlue1)
        Thisform.ycolor2=Rgb(nRed2,nGreen2,nBlue2)
    Endproc

    Procedure Init
        With Thisform
            .SetAll("mousepointer",15,"commandbutton")
            .SetAll("fontbold",.T.,"commandbutton")
            .SetAll("anchor",768,"commandbutton")
            .imgcanvas1.Left=This.Left
            .imgcanvas1.Top=This.Top
            .imgcanvas1.Width=This.Width
            .imgcanvas1.Height=This.Height-This.yb1.Height-2
            .SetAll("fontsize",8,Thisform)
        Endwith
    Endproc

    Procedure imgcanvas1.beforedraw
        This.Clear
        logfx=This.ogfx
        With _Screen.System.Drawing
            logfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias
            **this.clear(.color.black)

            Do Case
                Case Thisform.cas=1

                    color1=.Color.fromRGB(Thisform.ycolor1)
                    color2=.Color.fromRGB(Thisform.ycolor2)

                    br = .Drawing2D.LinearGradientBrush.New(This.Rectangle,color1,color2,Thisform.nmode,.F.)
                    * br.SetBlendTriangularShape(0.5,1.0)
                    logfx.FillRectangle(br,This.Rectangle)
                    br.Dispose()

                Case Thisform.cas=2
                    **triangular brush

                    color1=.Color.fromRGB(Thisform.ycolor1)
                    color2=.Color.fromRGB(Thisform.ycolor2)

                    br = .Drawing2D.LinearGradientBrush.New(This.Rectangle,color1,color2,Thisform.nmode,.F.)
                    br.SetBlendTriangularShape(0.5,1.0)
                    logfx.FillRectangle(br,This.Rectangle)
                    br.Dispose()

                Case Thisform.cas=3
                    **Non linear gradient ok
           
br =.Drawing2D.LinearGradientBrush.New(This.Rectangle,.Color.fromRGB(Thisform.ycolor1),.Color.fromRGB(Thisform.ycolor2),Thisform.nmode,.F.)
                    br.SetSigmaBellShape(0.5,1.0)
                    logfx.FillRectangle(br,This.Rectangle)
                    br.Dispose()

                Case Thisform.cas=4

                    *The code in the listing below, creates a gradient brush with 9olours that span the
                    *width of the brush making a rainbow.
                    br = .Drawing2D.LinearGradientBrush.New(This.Rectangle,.Color.Black,.Color.Black,0,.F.)
                    cb = .Drawing2D.ColorBlend.New(9)

                    For F=1 To 9
                        cb.Positions[f]=(F-1)/8
                        cb.ColorS=.Color.NewArray(.Color.Red,.Color.Orange,.Color.Yellow,.Color.Green,.Color.Blue,.Color.Indigo,.Color.Violet,.Color.magenta,.Color.cyan)
                        br.InterpolationColors=cb
                        logfx.FillRectangle(br,This.Rectangle)
                    Endfor

                    br.Dispose()

                Case Thisform.cas=5
                    **blends
                    br = .Drawing2D.LinearGradientBrush.New(This.Rectangle,.Color.Black,.Color.White,0,.F.)
                    bl=.Drawing2D.Blend.New()
                    bl.Factors = _Screen.System.Single.NewArray(0,0.1,0.5,0.7,1.0,0,1.0,0.5,0.3,0.2,0)
                    bl.Positions = _Screen.System.Single.NewArray(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)
                    br.Blend=bl
                    This.ogfx.FillRectangle(br,This.Rectangle)
                    br.Dispose()


                Case Thisform.cas=6
                    Local yPath As xfcGraphicsPath
                    point1=.Point.New(0.87*This. Rectangle.Width/2,0)
                    point2=.Point.New(0,This. Rectangle.Height)
                    point3=.Point.New(This. Rectangle.Width,This. Rectangle.Height)

                    yPath = .Drawing2D.GraphicsPath.New()
                    yPath.AddLine(point1,point2)
                    yPath.AddLine(point2,point3)
                    yPath.AddLine(point3,point1)
                    yPath.CloseFigure()
                    Local pgb As xfcPathGradientBrush
                    pgb=.Drawing2D.PathGradientBrush.New(yPath)

                    **colorArray= .color.new(.color.red,.color.green,.color.blue)
                    **pgb.SurroundColors[1]=colorArray
                    *pgb.SurroundColors[1] = .color.new(.Color.red,.color.green,.color.yellow)

                    Dimension colorArray(3) As Object
                    colorArray[1]=.Color.Red
                    colorArray[2]=.Color.Green
                    colorArray[3]=.Color.Blue
                    For i=1 To 3
                        pgb.SurroundColors[i]=colorArray(i)
                    Endfor


                    pgb.CenterColor=.Color.fromRGB(Thisform.ycolor1)
                    logfx.FillPath(pgb,yPath)

                    pgb.Dispose()

                    &&sun
                    Local loPath As xfcGraphicsPath
                    loPath = .Drawing2D.GraphicsPath.New()
                    loPath.AddEllipse(This.Left+20,This.Top+60, 80, 80)
                    Local loPathGradBrush As xfcPathGradientBrush
                    loPathGradBrush = .Drawing2D.PathGradientBrush.New(loPath)
                    loPathGradBrush.SurroundColors[1] =.Color.Yellow    && .color.new(.Color.red,.color.green,.color.blue)
                    *loPathGradBrush.SurroundColors[1] = .Color.yellow
                    *loPathGradBrush.SurroundColors[2] = .Color.blue
                    *loPathGradBrush.SurroundColors[3] = .Color.yellow

                    loPathGradBrush.CenterColor = .Color.Red
                    logfx.FillEllipse(loPathGradBrush, This.Left+20,This.Top+ 60, 80, 80)
                    loPathGradBrush.Dispose()

                Case Thisform.cas=7
                    This.Clear(.Color.Black)
                    *triangle grad
                    Local yPath As xfcGraphicsPath
                    point1=.Point.New(0.87*This. Rectangle.Width/2,10)
                    point2=.Point.New(10,This. Rectangle.Height-10)
                    point3=.Point.New(This. Rectangle.Width,This. Rectangle.Height-10)

                    yPath = .Drawing2D.GraphicsPath.New()
                    yPath.AddLine(point1,point2)
                    yPath.AddLine(point2,point3)
                    yPath.AddLine(point3,point1)
                    yPath.CloseFigure()

                    Pen = .Pen.New(.Color.gold, 6)
                    logfx.DrawPath(Pen,yPath)
                    color1=.Color.fromRGB(Thisform.ycolor1)
                    color2=.Color.fromRGB(Thisform.ycolor2)

                    br = .Drawing2D.LinearGradientBrush.New(This.Rectangle,color1,color2,Thisform.nmode,.F.)
                    logfx.FillPath(br,yPath)
            Endcase


            *texte
            Local loFont As xfcFont
            Local loBrush As xfcLinearGradientBrush
            Local loRectangleF As xfcRectangleF
            Local loSizeF As xfcSizeF

            ystring="GdiPlusX sous Visual Foxpro 9"
            loFont = .Font.New("Arial Black", 14,  .FontStyle.BoldItalic)
            loSizeF = logfx.MeasureString(ystring, loFont)
            loRectangleF =_Screen.System.Drawing.RectangleF.New(0,0,loSizeF.Width, loSizeF.Height)
            loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,.Color.Red,.Color.Green,3)
            logfx.DrawString(ystring, loFont,loBrush, loRectangleF)

            ystring="Yousfi Benameur November,2008"
            loFont = .Font.New("tahoma", 9,  .FontStyle.BoldItalic)
            loSizeF = logfx.MeasureString(ystring, loFont)
            loRectangleF =_Screen.System.Drawing.RectangleF.New(This.Width-loSizeF.Width-10,This.Height-loSizeF.Height-5,loSizeF.Width, loSizeF.Height)
            loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,.Color.Red,.Color.Green,3)
            logfx.DrawString(ystring, loFont,loBrush, loRectangleF)
        Endwith
        Return
    Endproc

    Procedure yb2.Click
        &&random color
        Thisform.cas=2
        Thisform.yrandom()
        Thisform.nmode=Thisform.nmode+1

        If Thisform.nmode>3
            Thisform.nmode=1
        Endi
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb3.Click
        Thisform.cas=3
        Thisform.yrandom
        Thisform.nmode=Thisform.nmode+1
        If Thisform.nmode>3
            Thisform.nmode=1
        Endi

        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb4.Click
        Thisform.cas=4
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb5.Click
        Thisform.cas=5
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb6.Click
        Thisform.cas=6
        Thisform.yrandom()
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb1.Click
        &&random color
        Thisform.cas=1
        Thisform.yrandom
        Thisform.nmode=Thisform.nmode+1

        If Thisform.nmode>3
            Thisform.nmode=1
        Endi
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb7.Click
        Thisform.cas=7
        Thisform.yrandom()
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb8.Click
        Thisform.imgcanvas1.oBmp.toClipboard()
        Run/n3 mspaint
        Inkey(2)
        loShell=Createobject("wscript.shell")
        loShell.sendKeys("^{v}")
    Endproc

    Procedure yb8.Init
        This.Picture=Home(1)+"graphics\icons\misc\camera.ico"
    Endproc

    Procedure label1.Click
        Local m.myvar
        TEXT to m.myvar noshow
This demo code makes some drawings with gdiplusX on imagcanvas control.
it overlaps points,paths,drawing2D,
pens, xfcGradientBrushes,surroundcolors,centercolors,...
it draws, fills areas...
it draws text with fonts,style,...
-Can capture the imgcanvas contents and show in Mspaint(can save as...)
-Can save directly with ths image format+width+height set to an image (in "images"
 folder created)
   November 2008
        ENDTEXT
        Messagebox(m.myvar,0+32+4096,"GdiplusX")
    Endproc

    Procedure Destroy
        Clea Events
    Endproc
Enddefine
*

*End Code

 

Make sure always having latest version stable of gdiplusX.
Make sure always having latest version stable of gdiplusX.
Make sure always having latest version stable of gdiplusX.
Make sure always having latest version stable of gdiplusX.

Make sure always having latest version stable of gdiplusX.

*This demo code makes some drawings with gdiplusX on imagcanvas control.
*it overlaps points,paths,drawing2D,
*pens, xfcGradientBrushes,surroundcolors,centercolors,...
*it draws, fills areas...
*it draws text with fonts,style,...
*-Can capture the imgcanvas contents and show in Mspaint(can save as...)

*Begin code
Publi m.yrep
m.yrep=Addbs(Justpath(Sys(16,1)))   && for a form : Sys(1271,This)))
If !Directory(m.yrep+"images")
    Md (m.yrep+"images")
Endi

Do Locfile("system.app") &&point to system.app
Set Classlib To Locfile("gdiplusX") AddI  &&point mandatory to gdiplusX class location
Publi yform
yform=Newobject("ysurround")
Release Classlib "gdiplusX"
yform.Show
Read Events
*
*
Define Class ysurround As Form
    Height = 626
    Width = 914
    ShowWindow = 2
    ShowTips = .T.
    AutoCenter = .T.
    Caption = "GdiPlusX  samples   Ellipses-Circles  "
    BackColor = Rgb(0,0,0)
    ycolor1 = 255
    ycolor2 = 1254
    nmode = 3
    cas = 1
    focusscale = 0.8
    Name = "Form1"

    Add Object imgcanvas1 As imgcanvas With ;
        Anchor = 15, ;
        Stretch = 2, ;
        Height = 564, ;
        Left = 0, ;
        Top = 2, ;
        Width = 912, ;
        Name = "Imgcanvas1"

    Add Object command1 As CommandButton With ;
        Top = 578, ;
        Left = 1, ;
        Height = 27, ;
        Width = 153, ;
        Anchor = 768, ;
        Caption = "Swith colors-FocusScale", ;
        ToolTipText = "Switch many times", ;
        Name = "Command1"


    Add Object command2 As CommandButton With ;
        Top = 578, ;
        Left = 228, ;
        Height = 27, ;
        Width = 153, ;
        Anchor = 768, ;
        Caption = "Swith colors-Normal", ;
        ToolTipText = "Switch many times", ;
        Name = "Command2"

    Add Object combo1 As ComboBox With ;
        Anchor = 768, ;
        Height = 24, ;
        Left = 157, ;
        Style = 2, ;
        ToolTipText = "FocusScale (0,1)", ;
        Top = 580, ;
        Width = 56, ;
        Name = "Combo1"


    Add Object command3 As CommandButton With ;
        Top = 579, ;
        Left = 387, ;
        Height = 27, ;
        Width = 132, ;
        Anchor = 768, ;
        Caption = "Switch  blend  Ellipse", ;
        ToolTipText = "Switch many times", ;
        Name = "Command3"

    Add Object command4 As CommandButton With ;
        Top = 579, ;
        Left = 658, ;
        Height = 27, ;
        Width = 146, ;
        Anchor = 768, ;
        Caption = "Switch Effets Surrounds", ;
        ToolTipText = "Switch many times", ;
        Name = "Command4"

    Add Object command5 As CommandButton With ;
        Top = 579, ;
        Left = 521, ;
        Height = 27, ;
        Width = 132, ;
        Anchor = 768, ;
        Caption = "Switch blend Circle", ;
        ToolTipText = "Switch many times", ;
        Name = "Command5"

    Add Object yb8 As CommandButton With ;
        Top = 578, ;
        Left = 843, ;
        Height = 39, ;
        Width = 61, ;
        Anchor = 768, ;
        Picture = "d:\yvfp\ysvg\apphoto.bmp", ;
        Caption = "", ;
        MousePointer = 15, ;
        ToolTipText = "Capture  image+View", ;
        BackColor = Rgb(128,0,255), ;
        Name = "yb8"

    Add Object label1 As Label With ;
        AutoSize = .T., ;
        FontBold = .T., ;
        FontSize = 22, ;
        Anchor = 768, ;
        BackStyle = 0, ;
        Caption = "?", ;
        Height = 37, ;
        Left = 817, ;
        MousePointer = 15, ;
        Top = 580, ;
        Width = 20, ;
        ForeColor = Rgb(0,255,0), ;
        ToolTipText = "Summary help", ;
        Name = "Label1"

    Procedure yrandom
        nRed1=Int(255*Rand() )
        nGreen1=Int(255*Rand() )
        nBlue1=Int(255*Rand() )

        nRed2=Int(255*Rand() )
        nGreen2=Int(255*Rand() )
        nBlue2 =Int(255*Rand() )
        Thisform.ycolor1=Rgb(nRed1,nGreen1,nBlue1)
        Thisform.ycolor2=Rgb(nRed2,nGreen2,nBlue2)
    Endproc

    Procedure Resize

        This.command1.Top=This.Height-This.command1.Height-5
        This.command2.Top=This.command1.Top
        This.combo1.Top=This.command1.Top
        This.command3.Top=This.command1.Top
        This.command4.Top=This.command1.Top
        This.yb8.Top=This.command1.Top
    Endproc

    Procedure Init

        Publi ii
        ii=0
        This.imgcanvas1.Left=This.Left
        This.imgcanvas1.Top=This.Top
        This.imgcanvas1.Width=This.Width
        This.imgcanvas1.Height=This.Height-This.command1.Top

        Thisform.ycolor1=Rgb(17,0,150)
        Thisform.ycolor2=Rgb(195,180,50)
        Thisform.nmode=0

        For i=1 To 10
            This.combo1.AddItem(Str(i/10,3,2) )
        Endfor
        This.combo1.ListIndex=8
        This.command1.Click
    Endproc

    Procedure Unload
        Try
            For i=1 To _Screen.FormCount
                If Lower(_Screen.Forms(i).Name)="ymain"
                    ymain.WindowState=0
                Endi
            Endfor
        Catch
        Endtry
    Endproc

    Procedure imgcanvas1.beforedraw
        Local pth As xfcGraphicsPath
        Local pgb As xfcPathGradientBrush
        Local logfx
        Local w,h
        w=This.Width
        h=This.Height

        This.Clear
        logfx=This.ogfx
        With _Screen.System.Drawing
            logfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias
            This.Clear(.Color.black)
            Do Case
                Case Thisform.cas=3
                    Local yPath As xfcGraphicsPath
                    w=This.rectangle.Width-40
                    h=This.rectangle.Height-40

                    point1=.Point.new(20,20)
                    point2=.Point.new(h,20)
                    point3=.Point.new(w,h)
                    point4=.Point.new(20,h)

                    yPath = .Drawing2D.GraphicsPath.new()
                    yPath.addellipse(20,20,w,h)
                    yPath.CloseFigure()


                    *draw rectangle
                    Pen = .Pen.new(.Color.gold, 6)
                    logfx.DrawPath(Pen,yPath)
                    Local pgb As xfcPathGradientBrush
                    pgb=.Drawing2D.PathGradientBrush.new(yPath)
                    Thisform.yrandom()
                    pgb.SurroundColors[1] = .Color.fromRGB(Thisform.ycolor1)
                    pgb.centercolor=.Color.fromRGB(Thisform.ycolor2)
                    pgb.SurroundColors=.Color.black
                    bl =.Drawing2D.Blend.new()
                    bl.Factors  =_Screen.System.Single.NewArray(1,0,1,0,1)
                    bl.Positions=_Screen.System.Single.NewArray(0,0.25,0.5,0.75,1)
                    pgb.Blend=bl

                    logfx.FillEllipse(pgb,20,20,w,h)
                    pgb.Dispose()

                Case Thisform.cas=30
                    Local yPath As xfcGraphicsPath
                    h=This.rectangle.Height-40
                    w=h

                    point1=.Point.new(80,80)
                    point2=.Point.new(h,80)
                    point3=.Point.new(h,h)
                    point4=.Point.new(80,h)

                    yPath = .Drawing2D.GraphicsPath.new()
                    yPath.addellipse(120,20,w,h)
                    yPath.CloseFigure()


                    *draw rectangle
                    Pen = .Pen.new(.Color.gold, 6)
                    logfx.DrawPath(Pen,yPath)

                    Local pgb As xfcPathGradientBrush
                    pgb=.Drawing2D.PathGradientBrush.new(yPath)
                    Thisform.yrandom()
                    pgb.SurroundColors[1] = .Color.fromRGB(Thisform.ycolor1)
                    pgb.centercolor=.Color.fromRGB(Thisform.ycolor2)
                    pgb.SurroundColors=.Color.black
                    bl =.Drawing2D.Blend.new()
                    bl.Factors  =_Screen.System.Single.NewArray(1,0,1,0,1)
                    bl.Positions=_Screen.System.Single.NewArray(0,0.25,0.5,0.75,1)
                    pgb.Blend=bl
        
                    logfx.FillEllipse(pgb,120,20,w,h)
                    pgb.Dispose()

                Case Thisform.cas=4
                    Local yPath As xfcGraphicsPath
                    w=This.rectangle.Width-40
                    h=This.rectangle.Height-40
                    point1=.Point.new(40,40)
                    point2=.Point.new(w,40)
                    point3=.Point.new(w,h)
                    point4=.Point.new(40,h)

                    yPath = .Drawing2D.GraphicsPath.new()
                    yPath.addellipse(20,20,w,h)
                    yPath.CloseFigure()

                    *draw rectangle
                    Pen = .Pen.new(.Color.gold, 6)
                    logfx.DrawPath(Pen,yPath)
                
                    Local pgb As xfcPathGradientBrush
                    pgb=.Drawing2D.PathGradientBrush.new(yPath)
                    Thisform.yrandom()
                    Dimension acolor(3)
                    acolor(1)=.Color.fromRGB(Thisform.ycolor1)
                    acolor(2)=.Color.fromRGB(Thisform.ycolor2)
                    acolor(3)=.Color.green
                    For i=1 To Alen(acolor)
                        pgb.SurroundColors[i] =acolor(i)
                    Endfor
                    Thisform.yrandom()
                    pgb.centercolor=.Color.fromRGB(Thisform.ycolor2)

                    logfx.FillEllipse(pgb,20,20,w,h)
                    pgb.Dispose()

    
                Case Thisform.cas=1 Or Thisform.cas=2 &&otherwise
        
                    pth=.Drawing2D.GraphicsPath.new()
                    pth.addellipse(50,50,0.8*w,0.8*h)
                    pgb=.Drawing2D.PathGradientBrush.new(pth)
                    pgb.centercolor   =.Color.fromRGB(Thisform.ycolor1)
                    pgb.SurroundColors=.Color.fromRGB(Thisform.ycolor2)
                    If Thisform.cas=1
                        pgb.FocusScales=.PointF.new(Thisform.focusscale,Thisform.focusscale)
                    Endi

                    Pen = .Pen.new(.Color.gold, 2)
                    logfx.DrawPath(Pen,pth)
                    logfx.FillEllipse(pgb,50,50,0.8*w,0.8*h)
            Endcase

            *texte
            Local loFont As xfcFont
            Local loBrush As xfcLinearGradientBrush
            Local loRectangleF As xfcRectangleF
            Local loSizeF As xfcSizeF

            ystring="GdiPlusX sous Visual Foxpro 9"
            loFont = .Font.new("Arial Black", 14,  .FontStyle.BoldItalic)
            loSizeF = logfx.MeasureString(ystring, loFont)
            loRectangleF =_Screen.System.Drawing.RectangleF.new(0,0,loSizeF.Width, loSizeF.Height)
            loBrush = .Drawing2D.LinearGradientBrush.new(loRectangleF,.Color.red,.Color.green,3)
            logfx.DrawString(ystring, loFont,loBrush, loRectangleF)

            ystring="Yousfi Benameur November,2008"
            loFont = .Font.new("tahoma", 9,  .FontStyle.BoldItalic)
            loSizeF = logfx.MeasureString(ystring, loFont)
            loRectangleF =_Screen.System.Drawing.RectangleF.new(This.Width-loSizeF.Width-10,This.Height-loSizeF.Height-5,loSizeF.Width, loSizeF.Height)
            loBrush = .Drawing2D.LinearGradientBrush.new(loRectangleF,.Color.red,.Color.green,3)
            logfx.DrawString(ystring, loFont,loBrush, loRectangleF)


        Endwith
        Return
    Endproc


    Procedure command1.Click
        &&random color
        Thisform.cas=1
        Thisform.yrandom()
        Thisform.nmode=Thisform.nmode+1
        If Thisform.nmode>3
            Thisform.nmode=0
        Endi

        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure command2.Click
        &&random color
        Thisform.cas=2
        Thisform.yrandom()
        Thisform.nmode=Thisform.nmode+1
        If Thisform.nmode>3
            Thisform.nmode=0
        Endi
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure combo1.Click
        Thisform.cas=1
        Thisform.focusscale=This.Value
        Thisform.command1.Click
    Endproc

    Procedure command3.Click
        Thisform.cas=3
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure command4.Click
        Thisform.cas=4
        Thisform.imgcanvas1.Draw()
    Endproc


    Procedure command5.Click
        Thisform.cas=30
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure yb8.Click

        Thisform.imgcanvas1.oBmp.toClipboard()
        Run/n3 mspaint
        Inkey(2)
        loShell=Createobject("wscript.shell")
        loShell.sendKeys("^{v}")
    Endproc

    Procedure yb8.Init
        This.Picture=Home(1)+"graphics\icons\misc\camera.ico"
    Endproc

    Procedure label1.Click
        Local m.myvar
        TEXT to m.myvar noshow
This demo code makes some drawings with gdiplusX on imagcanvas control.
it overlaps points,paths,drawing2D,
pens, xfcGradientBrushes,surroundcolors,centercolors,...
it draws, fills areas...
it draws text with fonts,style,...
-Can capture the imgcanvas contents and show in Mspaint(can save as...)
        ENDTEXT
        Messagebox(m.myvar,0+32+4096,"GdiplusX")
    Endproc
Procedure destroy
clea events
endproc

Enddefine
*

*End code

 

 Drawings with gdiplusX -part I
 Drawings with gdiplusX -part I
 Drawings with gdiplusX -part I
 Drawings with gdiplusX -part I

*Draw stars with a animated timer

*Begin code
Publi m.yrep
m.yrep=Addbs(Justpath(Sys(16,1)))   && for a form : Sys(1271,This)))
If !Directory(m.yrep+"images")
    Md (m.yrep+"images")
Endi

Do Locfile("system.app") &&point to system.app
Set Classlib To Locfile("gdiplusX") AddI  &&point mandatory to gdiplusX class location
Publi yform
yform=Newobject("ystar")
Release Classlib "gdiplusX"
yform.Show
Read Events
*
Define Class ystar As Form
    Height = 646
    Width = 1003
    ShowWindow = 2
    AutoCenter = .T.
    Caption = "GdiPlusX samples     three stars  "
    KeyPreview = .T.
    BackColor = Rgb(0,0,0)
    ycolor1 = ""
    ycolor2 = ""
    nmode = 3
    cas = 1
    Name = "Form1"

    Add Object imgcanvas1 As imgcanvas With ;
        Anchor = 15, ;
        Stretch = 2, ;
        Height = 648, ;
        Left = 0, ;
        Top = 0, ;
        Width = 1008, ;
        Name = "Imgcanvas1"

    Add Object timer1 As Timer With ;
        Top = 36, ;
        Left = 672, ;
        Height = 23, ;
        Width = 23, ;
        Interval = 1000, ;
        Name = "Timer1"

    Procedure ypolygon
        Lparameters nb
        *,r,pr
        r=180
        pr=90
        Create Cursor ycoord (nx N(4,0),ny N(4,0))
        Set Safe On
        xc=0.5*Thisform.Width
        yc=1.1*Thisform.Height/2

        For i=0 To 2*Pi() Step 2*Pi()/nb
            x=xc+r*Cos(i-Pi()/2)
            Y=yc+r*Sin(i-Pi()/2)
            Sele ycoord
            Appe Blan
            Repl nx With x,ny With Y
            x1=xc+pr*Cos(i-Pi()/2+Pi()/nb)
            y1=yc+pr*Sin(i-Pi()/2+Pi()/nb)

            Sele ycoord
            Appe Blan
            Repl nx With x1,ny With y1
        Endfor

        &&montage fichier polygon
        Sele  ycoord
        Count To xx For Not Deleted()
        Go Top
        Dimension  Mat0(xx,2)

        i=1
        v=""
        Do While Not Eof()
            If Not Deleted()
                Mat0(i,1)=nx
                Mat0(i,2)=ny
                v=v+"Mat0("+Allt(Str(i))+",1)="+Allt(Str(nx))+Chr(13)+"Mat0("+Allt(Str(i))+",2)="+Allt(Str(ny))+Chr(13)

                i=i+1
            Endi
            Skip
        Enddo
        vv="dimension Mat0("+Allt(Str(i-1))+",2)"+Chr(13) +v
        TEXT to myvar noshow
        <<vv>>
        ENDTEXT
    Endproc

    Procedure ypat
        With _Screen.System.Drawing
            p1=.Point.new(512,184)
            p2=.Point.new(568,307)
            p3=.Point.new(702,322)
            p4=.Point.new(602,413)
            p5=.Point.new(630,546)
            p6=.Point.new(512,479)
            p7=.Point.new(394,546)
            p8=.Point.new(422,413)
            p9=.Point.new(322,322)
            p10=.Point.new(456,307)
            p11=.Point.new(512,184)

            pth=.drawing2d.GraphicsPath.new()
            pth.AddLine(p1,p2)
            pth.AddLine(p2,p3)
            pth.AddLine(p3,p4)
            pth.AddLine(p4,p5)
            pth.AddLine(p5,p6)
            pth.AddLine(p6,p7)
            pth.AddLine(p7,p8)
            pth.AddLine(p9,p10)
            pth.AddLine(p10,p11)

            pth.closeFigure()
        Endwith
        Return pth
    Endproc

    Procedure Init
        Publi ii,pth
        ii=0
        This.Width=Sysmetric(1)
        This.Height=Sysmetric(2)
        This.Left=0
        This.Top=0
        This.imgcanvas1.Left=This.Left
        This.imgcanvas1.Top=This.Top
        This.imgcanvas1.Width=This.Width
        This.imgcanvas1.Height=This.Height

        Thisform.ycolor1=255
        Thisform.ycolor2=Rgb(0,255,0)
    Endproc

    Procedure KeyPress
        Lparameters nKeyCode, nShiftAltCtrl
        If nKeyCode=27
            Thisform.timer1.Enabled=.F.
        Endi
    Endproc

    Procedure Unload
        Try
            For i=1 To _Screen.FormCount
                If Lower(_Screen.Forms(i).Name)="ymain"
                    ymain.WindowState=0
                Endi
            Endfor
        Catch
        Endtry
    Endproc

    Procedure imgcanvas1.beforedraw
        Local yPath As xfcGraphicsPath
        Local pgb As xfcPathGradientBrush
        Local logfx
        Local w,h

        This.Clear
        logfx=This.ogfx
        With _Screen.System.Drawing
            logfx.SmoothingMode = .drawing2d.SmoothingMode.AntiAlias
            This.Clear(.Color.black)
            Do Case
                Case Thisform.cas=1

                    Thisform.ypat()
                    pgb=.drawing2d.PathGradientBrush.new(pth)
                    pgb.CenterColor=.Color.White
                    pgb.SurroundColors=.Color.green
                    bl=.drawing2d.Blend.new()
                    bl.Factors=_Screen.System.Single.newArray(1,0,1,0,1)
                    bl.Positions= _Screen.System.Single.newArray(0,0.25,0.5,0.75,1)
                    pgb.Blend=bl
                    logfx.FillPath(pgb,pth)
                    pgb.dispose()

                Case Thisform.cas=2
                    Thisform.ypat()

                    Pen = .Pen.new(.Color.red, 4)
                    logfx.DrawPath(Pen,pth)
                    pgb=.drawing2d.PathGradientBrush.new(pth)
                    pgb.CenterColor=.Color.White
                    pgb.SurroundColors=.Color.green    &&Black
                    bl=.drawing2d.Blend.new()
                    bl.Factors=_Screen.System.Single.newArray(1,0,1,0,1,0,1,0,0,1)
                    bl.Positions= _Screen.System.Single.newArray(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,1)
                    pgb.Blend=bl
                    logfx.FillPath(pgb,pth)
                    pgb.dispose()

                Case Thisform.cas=3
                    pgb = .drawing2d.LinearGradientBrush.new(This.rectangle,.Color.black,.Color.black,0,.F.)
                    cb = .drawing2d.ColorBlend.new(7)
                    For F=1 To 7
                        cb.Positions[f]=(F-1)/6
                        cb.ColorS=.Color.newArray(.Color.red,.Color.Orange,.Color.Yellow,.Color.green,.Color.Blue,.Color.Indigo,.Color.Violet)
                        pgb.InterpolationColors=cb           &&error interpolationcolors_assign   lineo 7659
                        *pgb.FocusScales=.PointF.new(0.5,0.3)
                        logfx.FillPath(pgb,pth)
                    Endfor
                    pgb.dispose()


                Case Thisform.cas=4
                    Thisform.ypat()
                    pgb=.drawing2d.PathGradientBrush.new(pth)
                    pgb.CenterColor=.Color.gold

                    Dimension acolor(7)
                    acolor(1)=.Color.red
                    acolor(2)=.Color.cyan
                    acolor(3)=.Color.green
                    acolor(4)=.Color.Yellow
                    acolor(5)=.Color.brown
                    acolor(6)=.Color.Blue
                    acolor(7)=.Color.Violet

                    For i=1 To 7
                        pgb.SurroundColors(i)=acolor(i)
                    Endfor

                    *bl=.Drawing2d.Blend.New()
                    *bl.Factors=_screen.system.single.newArray(1,0,1,0,1)
                    *bl.Positions= _Screen.System.Single.NewArray(0,0.25,0.5,0.75,1)
                    *pgb.Blend=bl
                    logfx.FillPath(pgb,pth)

                    pgb.dispose()

            Endcase


            *texte
            Local loFont As xfcFont
            Local loBrush As xfcLinearGradientBrush
            Local loRectangleF As xfcRectangleF
            Local loSizeF As xfcSizeF

            ystring="GdiPlusX sous Visual Foxpro 9"
            loFont = .Font.new("Arial Black", 14,  .FontStyle.BoldItalic)
            loSizeF = logfx.MeasureString(ystring, loFont)
            loRectangleF =_Screen.System.Drawing.RectangleF.new(0,0,loSizeF.Width, loSizeF.Height)
            loBrush = .drawing2d.LinearGradientBrush.new(loRectangleF,.Color.red,.Color.green,3)
            logfx.DrawString(ystring, loFont,loBrush, loRectangleF)

            ystring="Yousfi Benameur November,2008"
            loFont = .Font.new("tahoma", 9,  .FontStyle.BoldItalic)
            loSizeF = logfx.MeasureString(ystring, loFont)
            loRectangleF =_Screen.System.Drawing.RectangleF.new(This.Width-loSizeF.Width-10,This.Height-loSizeF.Height-5,loSizeF.Width, loSizeF.Height)
            loBrush = .drawing2d.LinearGradientBrush.new(loRectangleF,.Color.red,.Color.green,3)
            logfx.DrawString(ystring, loFont,loBrush, loRectangleF)

        Endwith
        Return
    Endproc

    Procedure timer1.Timer
        ii=ii+1
        If ii>4
            ii=1
        Endi
        Thisform.cas=ii
        Thisform.imgcanvas1.Draw()
    Endproc

    Procedure Destroy
        Clea Events
    Endproc

Enddefine
*

*-- End Code

 

the 4th star is not drawn well?? maybe yet a system.app problem ?
the 4th star is not drawn well?? maybe yet a system.app problem ?
the 4th star is not drawn well?? maybe yet a system.app problem ?
the 4th star is not drawn well?? maybe yet a system.app problem ?

the 4th star is not drawn well?? maybe yet a system.app problem ?

To be informed of the latest articles, subscribe:
Comment on this post
P
VERY GOOD
Reply