A gdiplusX animated sample with many objects - drawStringW

Published on by Yousfi Benameur


this code asks to point to gdiplusX class (for use of imgcanvas class) to make it working.
it draws curves as sinusoides(sin & cos)
it retrieves online the values drawn.
it draws a clock.
the drawing is not fast because vfp have to administrate many events at one time (many timers)
its simply an illustration of gdiplusX samplings combining many functions and effects as:

{Drawing2D, smoothingMode, rectangleF, linearGradientBrush, drawline, drawEllipse, drawRectangle, fillEllipse, FILLPATH, drawPath, translateTransform, resetTransform, measureString, drawString, renderMode}

first an animated gif is downloaded from the web to use in code (can replace with any disc image)
Note: this sample was posted on Foxite many years ago.


Click on code to select [then copy] -click outside to deselect

   
*1*
set defa to addbs(justpath(sys(16,1)))
_screen.windowstate=1
set talk off

*download a web animated web GIF image  (or point to any jpeg image on disc)
*named ystar.gif (in source folder)

Declare Integer Sleep In kernel32 Integer
Declare Integer URLDownloadToFile In urlmon.Dll Integer pCaller, String szURL, String szFileName, Integer dwReserved, Integer lpfnCB
Declare Integer DeleteUrlCacheEntry In wininet String lpszUrlName

lcDownloadURL = "https://s-media-cache-ak0.pinimg.com/originals/e1/a0/ef/e1a0ef685ab2c885a3b837db6f6ebd6d.gif"
lcDownloadLoc ="ystar.gif"
lnResult = DeleteUrlCacheEntry(lcDownloadURL)
lnResult = URLDownloadToFile(0, lcDownloadURL, lcDownloadLoc , 0,0)
If lnResult = 0
    Wait Window "Download "+lcDownloadLoc +"  Complete" Nowait
*Else
*!*  Messagebox("Download fails")
Endi

set classlib to locfile('gdiplusX.vcx','vcx') addi

publi yform
yform=newObject("asup")
release classlib "gdiplusX.vcx"
yform.show
read events
retu
*
DEFINE CLASS asup AS form
Height = 600
Width = 1004
ShowWindow = 2
AutoCenter = .T.
Picture = "ystar.gif"
Caption = "Sinusoides---"
WindowState = 2
BackColor = RGB(0,0,0)
teta = 0
count = 0
xx = .F.

ADD OBJECT imgcanvas1 AS imgcanvas WITH ;
Anchor = 0, ;
Height = 432, ;
Left = 0, ;
Top = 0, ;
Width = 792, ;
rendermode = 4, ;
Name = "Imgcanvas1"

ADD OBJECT timer1 AS timer WITH ;
Top = 60, ;
Left = 72, ;
Height = 23, ;
Width = 23, ;
Interval = 5, ;
Name = "Timer1"

ADD OBJECT imgcanvas2 AS imgcanvas WITH ;
BackStyle = 0, ;
Height = 84, ;
Left = 252, ;
Top = 432, ;
Width = 528, ;
rendermode = 4, ;
Name = "Imgcanvas2"

ADD OBJECT imgcanvas3 AS imgcanvas WITH ;
BackStyle = 0, ;
Height = 589, ;
Left = 790, ;
Top = -1, ;
Width = 217, ;
rendermode = 4, ;
Name = "Imgcanvas3"

ADD OBJECT yclock_continous1 AS yclock_continous WITH ;
Top = 432, ;
Left = 12, ;
Width = 156, ;
Height = 144, ;
isarrowseconds = .F., ;
isseconds = .F., ;
istime = .F., ;
Name = "Yclock_continous1", ;
Imgcanvas1.Name = "Imgcanvas1", ;
Timer1.Name = "Timer1"

PROCEDURE Destroy
clea events
ENDPROC

PROCEDURE Init
if _screen.visible
_screen.windowstate=1
endi
this.setall("rendermode",4,"imgcanvas")
this.setall("drawWhenInvisible",.t.,"imgcanvas")
ENDPROC

PROCEDURE imgcanvas1.setup
this.clear(_screen.system.drawing.color.black)
thisform.teta=0
this.draw
ENDPROC

PROCEDURE imgcanvas1.beforedraw
	loGfx=this.ogfx
WITH _SCREEN.System.Drawing
loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias
w=180
xc=(w)/2
yc=(w)/2

color1=.color.green
ystring="COS"
 loFont = .Font.New("tahoma", 14,  .FontStyle.BoldItalic)
	loSizeF = loGfx.MeasureString(ystring, loFont)
	loRectangleF =_screen.system.Drawing.RectangleF.New(2*w+10,5,loSizeF.Width, loSizeF.Height)
	loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,color1,Color1,3)
	loGfx.DrawString(ystring, loFont,loBrush, loRectangleF)

	color1=.color.white
ystring="SIN"
 loFont = .Font.New("tahoma", 14,  .FontStyle.BoldItalic)
	loSizeF = loGfx.MeasureString(ystring, loFont)
	loRectangleF =_screen.system.Drawing.RectangleF.New(2*w+10,25,loSizeF.Width, loSizeF.Height)
	loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,color1,Color1,3)
	loGfx.DrawString(ystring, loFont,loBrush, loRectangleF)

if thisform.teta>2*pi()
thisform.count=-1
thisform.imgcanvas2.clear(.color.transparent)

thisform.imgcanvas3.clear(.color.transparent)
thisform.xx=-15
this.clear(.color.transparent)
thisform.teta=0   &&pi()/2
endi

logfx.translateTransform(xc,yc)
pen=.pen.new(.color.green,2)
logfx.drawEllipse(pen,0,0,w,w)
pen=.pen.new(.color.gold,2)
logfx.drawline(pen,0,w/2,w,w/2)
logfx.drawline(pen,w/2,0,w/2,w)

logfx.translateTransform(xc,yc)
pen=.pen.new(.color.red,1)
logfx.drawline(pen,w+1,0,this.width-10,0)
logfx.drawline(pen,w+1,-w+1,w+1,w)

logfx.drawLine(pen,0,0,0.5*w*cos(thisform.teta-pi()/2),0.5*w*sin(thisform.teta-pi()/2) )
pen=.pen.new(.color.white,1)
logfx.drawLine(pen,0,0,0.25*w*cos(thisform.teta-pi()/2),0.25*w*sin(thisform.teta-pi()/2) )

logfx.fillEllipse(.solidbrush.new(.color.gold),0.5*w*cos(thisform.teta-pi()/2),0.5*w*sin(thisform.teta-pi()/2),5,5 )

&&cos curve
pen=.pen.new(.color.green,1)
loRect=.rectangle.new(w+1+180/(pi())*(thisform.teta),-0.5*w*cos(thisform.teta),1,1 )
logfx.drawRectangle(pen,lorect)

&&sin curve
pen=.pen.new(.color.white,1)
loRect=.rectangle.new(w+1+180/(pi())*(thisform.teta),-0.5*w*sin(thisform.teta),1,1 )
logfx.drawRectangle(pen,lorect)
loGfx.ResetTransform()
endwith
retu
ENDPROC

PROCEDURE timer1.Timer
thisform.teta=thisform.teta+pi()/180
thisform.imgcanvas1.draw
thisform.imgcanvas2.draw
if thisform.count=0 or thisform.count=1
thisform.imgcanvas3.draw
endi
thisform.count=thisform.count+1
if mod(thisform.count,10)=0
thisform.imgcanvas3.draw
endi
if lastkey()=27
this.enabled=.f.
endi
ENDPROC

PROCEDURE imgcanvas2.beforedraw
loGfx=this.ogfx
WITH _SCREEN.System.Drawing
loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias
*texte
this.clear(.color.transparent)
LOCAL loFont AS xfcFont
LOCAL loBrush AS xfcLinearGradientBrush
LOCAL loRectangleF As xfcRectangleF
LOCAL loSizeF AS xfcSizeF
color1=.color.red
color2=.color.green
deg=trans((thisform.teta-pi()/2)*180/pi()+90,"999")
ystring="Deg= "+deg+"  Rad="+trans((thisform.teta),"999.99")+   " rad    SIN= "+trans(sin(thisform.teta),"99.9999")+"    COS= "+trans(cos(thisform.teta-pi()/2),"99.9999")
   loFont = .Font.New("tahoma", 12,  .FontStyle.BoldItalic)
	loSizeF = loGfx.MeasureString(ystring, loFont)
	loRectangleF =_screen.system.Drawing.RectangleF.New((this.width-loSizeF.width)/2,this.height/2+loSizeF.height+5,loSizeF.Width, loSizeF.Height)
	loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,color1,Color2,3)    &&color2 enlevée
	loGfx.DrawString(ystring, loFont,loBrush, loRectangleF)
endwith
ENDPROC

PROCEDURE imgcanvas3.beforedraw
loGfx=this.ogfx
WITH _SCREEN.System.Drawing
loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias
*texte
LOCAL loFont AS xfcFont
LOCAL loBrush AS xfcLinearGradientBrush
LOCAL loRectangleF As xfcRectangleF
LOCAL loSizeF AS xfcSizeF
color1=.color.red
color2=.color.white

do case
case thisform.count=0
ystring="Deg   Rad         SINUS            COSINUS"
case thisform.count=1
ystring=" "+trans(0,"99999")+"  "+trans(0,"9999.99")+"         "+trans(sin(0),"99.9999")+"       "+trans(cos(0),"99.9999")
otherwise
deg=trans( (thisform.teta)*180/pi(),"999")        &&-pi()/2)*180/pi()+90,"999")
ystring=" "+deg+"  "+trans((thisform.teta),"9999.99")+"         "+trans(sin(thisform.teta),"99.9999")+"       "+trans(cos(thisform.teta),"99.9999")
endcase
   loFont = .Font.New("tahoma", 8,  .FontStyle.BoldItalic)
	loSizeF = loGfx.MeasureString(ystring, loFont)
	loRectangleF =_screen.system.Drawing.RectangleF.New(5,thisform.xx,loSizeF.Width, loSizeF.Height)
	loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,color1,Color2,3)
	loGfx.DrawString(ystring, loFont,loBrush, loRectangleF)
thisform.xx=thisform.xx+15
endwith
ENDPROC

PROCEDURE imgcanvas3.setup
thisform.xx=-15
ENDPROC
ENDDEFINE
*
*-- EndDefine: asup
*
DEFINE CLASS yclock_continous AS container
Width = 205
Height = 204
BackStyle = 0
BorderWidth = 0
MousePointer = 15
isgraduation = .T.
ispicture = ".F."
istime = .T.
isseconds = .T.
arrowcolor1 = 255
arrowcolor2 = (rgb(0,255,0))
issound = .F.
isarrowseconds = .T.
Name = "yclock_continous"

ADD OBJECT imgcanvas1 AS imgcanvas WITH ;
Height = 204, ;
Left = 0, ;
Top = 0, ;
Width = 204, ;
Name = "Imgcanvas1"

ADD OBJECT timer1 AS timer WITH ;
Top = 156, ;
Left = 12, ;
Height = 23, ;
Width = 23, ;
Interval = 100, ;
Name = "Timer1"

PROCEDURE MouseMove
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton = 1 && Left button
try
this.mousepointer=15
	THIS.parent.XOffset = nXCoord - THIS.Left
	THIS.parent.YOffset = nYCoord - THIS.Top
	THIS.Drag
catch
endtry
	else
	this.mousepointer=5
ENDIF
ENDPROC

PROCEDURE DragDrop
LPARAMETERS oSource, nXCoord, nYCoord
try
THIS.Parent.DragDrop(oSource, nXCoord, nYCoord)
catch
endtry
ENDPROC

PROCEDURE Init
try
this.parent.addProperty("xoffset",0)
this.parent.addProperty("yoffset",0)
catch
endtry
ENDPROC

PROCEDURE imgcanvas1.beforedraw
		LOCAL logfx as xfcGraphics
		logfx = This.oGfx
		WITH _SCREEN.system.Drawing
			logfx.Clear(.Color.Transparent)
			loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias

			* gray outer
			loRect1 = .Rectangle.new(6,6,This.Width-12,This.width-12)
		path1 = .Drawing2D.GraphicsPath.New()
	   path1.AddEllipse(loRect1)
			loPen1 = .Pen.new(.Color.black,6)
			loGfx.DrawPath(loPen1,path1)

			* black inner
			*loRect2 = lorect1
			*lorect2.inflate(-1,-1)

			loBrush1 = .SolidBrush.New(.Color.black)
			loGfx.FillPath(loBrush1,Path1)

			* highlight
			loRect3 = .RectangleF.New(10,10,This.Width - 20 ,this.height - 20)
			path3 = .Drawing2D.GraphicsPath.New(loRect3)
			 path3.AddEllipse(loRect3)

			loBrush2 = .Drawing2D.LinearGradientBrush.new(loRect3,.Color.FromRGB(165,165,165),.Color.FromRGB(33,33,33),1)
			loGfx.FillPath(loBrush2,Path3)

local tetas
tetas=val(substr(time(25),7,2))*pi()/30+val(substr(time(25),10,2))*pi()/3000

if this.parent.isSeconds=.t.
&& seconds
rs=0.15*this.width/2
*tetas=val(substr(time(),7,2))*pi()/30
*tetas=val(substr(time(25),7,2))*pi()/30+val(substr(time(25),10,2))*pi()/3000
pen=.pen.new(.color.green,2)

logfx.translateTransform(this.width/2,0.75*this.height)
logfx.drawLine(pen,0,0,rs*cos(tetas-pi()/2),rs*sin(tetas-pi()/2) )

*graduations
pen=.pen.new(.color.gold,2)
for i=1 to 12
logfx.drawline(pen,0.45*2*rs*cos(i*pi()/6-pi()/2),0.45*2*rs*sin(i*pi()/6-pi()/2),0.55*2*rs*cos(i*pi()/6-pi()/2),0.55*2*rs*sin(i*pi()/6-pi()/2))
endfor

*petit rond secondes
loRect2=.rectangle.new(-3,-3,6,6)
*loGfx.fillEllipse(.solidBrush.new(.color.red),loRect2)
br = .Drawing2D.LinearGradientBrush.New(loRect2,.color.black,.Color.gray,2)
loGfx.fillEllipse(br,loRect2)
pen=.pen.new(.color.green,2)
loGfx.drawEllipse(pen,loRect2)
loGfx.ResetTransform()
endi

*12 clock graduations
local r,ymin,yhour,tetah,tetam,rh
******
logfx.translateTransform(this.width/2,this.height/2)

&&grande aiguille secondes
r=0.90*this.width
pen=.pen.new(.color.gold,2)
for i=1 to 12
logfx.drawline(pen,0.45*r*cos(i*pi()/6-pi()/2),0.45*r*sin(i*pi()/6-pi()/2),0.55*r*cos(i*pi()/6-pi()/2),0.55*r*sin(i*pi()/6-pi()/2))
endfor

r=0.90*this.width
pen=.pen.new(.color.gold,2)
for i=1 to 12
logfx.drawline(pen,0.45*r*cos(i*pi()/6-pi()/2),0.45*r*sin(i*pi()/6-pi()/2),0.55*r*cos(i*pi()/6-pi()/2),0.55*r*sin(i*pi()/6-pi()/2))
endfor

if this.parent.isGraduation=.t.
*graduations secondaires
pen=.pen.new(.color.gold,1)
for i=1 to 60
logfx.drawline(pen,0.45*r*cos(i*pi()/30-pi()/2),0.45*r*sin(i*pi()/30-pi()/2),0.50*r*cos(i*pi()/30-pi()/2),0.50*r*sin(i*pi()/30-pi()/2))
endfor
endi
*****
*aiguilles hour+min
ymin =val(substr(time(),4,2))
tetam=ymin*pi()/30
yhour=val(substr(time(),1,2))
if yhour>12
yhour=yhour-12
endi
tetah=(yhour+ymin/60)*pi()/6

rh=0.6*this.width/2
rm=0.75*this.width/2
pen=.pen.new(.color.red,2)

*logfx.drawLine(pen,0,0,rh*cos(tetah-pi()/2),rh*sin(tetah-pi()/2) )  &&aiguille H linéaire
*logfx.drawLine(pen,0,0,rm*cos(tetam-pi()/2),rm*sin(tetam-pi()/2) )  &&aiguille min linéaire
if this.parent.isArrowSeconds=.t.
rs=rm
logfx.drawLine(pen,0,0,rs*cos(tetas-pi()/2),rs*sin(tetas-pi()/2) )
endi

&&aiguille composite heures
r1=0.2*rh
beta=20
color1=.color.fromRGB(this.parent.ArrowColor1)  &&couleur1 gradient aiguille
color2=.color.fromRGB(this.parent.ArrowColor2)  &&couleur2 gradient aiguille

p0 =.pointF.new(0,0)
p1 =.pointF.new( r1*cos(tetah-pi()/2-pi()/beta),r1*sin(tetah-pi()/2-pi()/beta) )
p1_=.pointF.new( r1*cos(tetah-pi()/2+pi()/beta),r1*sin(tetah-pi()/2+pi()/beta) )
p2 =.pointF.new(rh*cos(tetah-pi()/2),rh*sin(tetah-pi()/2) )

ypath1 = .Drawing2D.GraphicsPath.New()
dimension points(4)
points(1)=p0
points(2)=P1
points(4)=p1_
points(3)=p2
ypath1.addlines(@points)
ypath1.CloseFigure()

br= .Drawing2D.LinearGradientBrush.New(this.rectangle,Color1,Color2,3)
logfx.fillpath(br,ypath1)
pen=.pen.new(.color.gold,1)
logfx.drawPath(pen,ypath1)

&&aiguille composite minutes
r1=0.2*rm
p0 =.pointF.new(0,0)
p1 =.pointF.new( r1*cos(tetam-pi()/2-pi()/beta),r1*sin(tetam-pi()/2-pi()/beta) )
p1_=.pointF.new( r1*cos(tetam-pi()/2+pi()/beta),r1*sin(tetam-pi()/2+pi()/beta) )
p2 =.pointF.new(rm*cos(tetam-pi()/2),rm*sin(tetam-pi()/2) )

ypath2 = .Drawing2D.GraphicsPath.New()
dimension points(4)
points(1)=p0
points(2)=P1
points(4)=p1_
points(3)=p2
ypath2.addlines(@points)
ypath2.CloseFigure()

br= .Drawing2D.LinearGradientBrush.New(this.rectangle,Color1,Color2,3)
logfx.fillpath(br,ypath2)
pen=.pen.new(.color.gold,1)
logfx.drawPath(pen,ypath2)

&&petit rond central
loRect1=.rectangle.new(-6,-6,12,12)
br = .Drawing2D.LinearGradientBrush.New(loRect1,.color.black,.Color.gray,3)
loGfx.fillEllipse(br,loRect1)
pen=.pen.new(.color.GREEN,1)
loGfx.drawEllipse(pen,loRect1)
loGfx.ResetTransform()

pen.dispose()
br.dispose()

loGfx.ResetTransform()

if this.parent.isTime=.t.
*texte
LOCAL loFont AS xfcFont
LOCAL loBrush AS xfcLinearGradientBrush
LOCAL loRectangleF As xfcRectangleF
LOCAL loSizeF AS xfcSizeF
ystring=time()
   loFont = .Font.New("tahoma", 9,  .FontStyle.BoldItalic)
	loSizeF = loGfx.MeasureString(ystring, loFont)
	loRectangleF =_screen.system.Drawing.RectangleF.New((this.width-loSizeF.width)/2,this.height/2+loSizeF.height+5,loSizeF.Width, loSizeF.Height)
	loBrush = .Drawing2D.LinearGradientBrush.New(loRectangleF,color1,Color1,3)    &&color2 enlevée
	loGfx.DrawString(ystring, loFont,loBrush, loRectangleF)
endi

if this.parent.isSound=.t.
*hour
if substr(time(),4,2)=="00" and substr(time(),7,2)=="00"
TRY
					LOCAL lcBell
					lcBell = SET("Bell")
					SET BELL TO (ADDBS(GETENV('windir')))+"MEDIA\tada.WAV"
					?? CHR(7)
					SET BELL TO (lcBell)
				CATCH
ENDTRY
endi
*1/2 hour
if substr(time(),4,2)=="30" and substr(time(),7,2)=="00"
TRY
					LOCAL lcBell
					lcBell = SET("Bell")
					SET BELL TO (ADDBS(GETENV('windir')))+"MEDIA\ding.WAV"
					?? CHR(7)
					SET BELL TO (lcBell)
				CATCH
ENDTRY
endi
endi
ENDWITH
retu
ENDPROC

PROCEDURE imgcanvas1.setup
with this.parent
.width=max(.width,.height)
.height=.width
endwith

with this
.top=6
.left=6
.width=.parent.width-12
.height=.parent.height-12
.rendermode = 4
.drawwheninvisible = .T.
.draw
endwith
ENDPROC

PROCEDURE timer1.Timer
if this.parent.enabled=.t.
this.enabled=.t.
this.parent.imgcanvas1.draw
else
this.enabled=.f.
endi
ENDPROC

ENDDEFINE
*
*-- EndDefine: yclock_continous


A gdiplusX animated sample with many objects - drawStringW
A gdiplusX animated sample with many objects - drawStringW
A gdiplusX animated sample with many objects - drawStringW

Click on code to select [then copy] -click outside to deselect

         
*2*
*using unicode string in gdiplusX
*updated on 10 february 2017
*this code draw an unicode text (here arabic) on any image with gdiplusX
*prepare unicode text an save it as unicode mandatory (here arabic.txt)
*the gdiplusX function drawStringW (drawstring for non unicode) makes the job.
*for occidental strings use only DrawString syntax.
*this first step is to create the unicode txt file(can prepare it manually and skip this)
Local m.myvar
TEXT to m.myvar noshow
//4qBkUGQwZGBiAAJwZEBkIGNwYxBkoGIABGBicGNQYxBiAAJwZEBi4GRAZKBkEGSgYMBiAAKAZBBjYGRAYgACcGRAYlBkUGQwYnBkYGJwYqBiAAJwZEBkUGJwZEBkoGKQYgACcGRAY2Bi4GRQYpBiAAJwZEBioGSgYgADMGLgZRBjEGRwYnBiAAOQZGBi8GIAAqBkIGRAYvBkcGDQAKACAARQZGBjUGKAYgACcGRAYxBiYGSgYzBiAAJwZEBkUGLwZKBjEGIAAnBkQGOQYnBkUGIABEBkEGMQZKBkIGIAAnBkQGOQYnBjUGRQYpBiAAJwZEBigGJwYxBkoGMwZKBikGDAYgAEEGSgYgAEYGSAZBBkUGKAYxBiAAMgAwADEAMQAMBg0ACgAgAEUGRgYgAEEGMQY2BiAAJwZEBkAGHSAoBkoGLgAjBjMGLgAsBkoGHSAgACAAQQZKBiAAJwZEBjMGJwYtBikGIAAnBkQGQwYxBkgGSgYpBiAAJwZEBkEGMQZGBjMGSgYpBi4AIAA=
ENDTEXT
Set Safe Off
Strtofile(Strconv(m.myvar,14),"arabic.txt")


*second step
Local lcFile,loPict
lcFile="arabic.txt"     &&Getfile('txt')   && any txt file,your saved unicode txt file in any language(notepad can do that with unicode saving option or utf-8)

loPict=Getpict()
Do Locfile("System.App")
Local N, x, Y, lnColor
Local loBmp As xfcBitmap, loGfx As xfcGraphics, loFont As xfcFont
Local loBrush As xfcSolidBrush
Local loString1,loString2

* Arabic
loString1 = "Arabic"
loString2 =Filetostr(lcFile)   &&unicode
*for utf-8 text -->> strconv(filetostr(lcFile),12)-->> &¬epad saved utf-8 to unicode string

With _Screen.System.Drawing
	loFont = .Font.New("Tahoma", 14)
	loBmp = .Bitmap.New(800,600)
	loGfx = .Graphics.FromImage(loBmp)
	loGfx.Clear(.Color.White)
	loGfx.drawImage(.Image.fromfile(loPict),0,0,800,600)
	loGfx.DrawString("Gdi+X Drawing Unicodes---DrawStringW()", loFont,;
		.Brushes.Blue, 10,5)
	lnColor = Rgb(255,255,255)

	* Create a SolidBrush with randomic color
	loBrush = .SolidBrush.New(.Color.FromRGB(lnColor))

	* Draw the language name
	loGfx.DrawString(loString1, .Font.New("Tahoma", 14),.Brushes.Red, 30, 40)

	* Draw the text in Unicodes
	loRectangleF =.RectangleF.New(0,250,795, 500)
	sf = .StringFormat.GenericTypographic.Clone()
	sf.Alignment = 2 && StringAlignment.right
	sf.LineAlignment = 1 && StringAlignment.Center
	=DrawStringW(loGfx, loString2, loFont,loBrush,loRectangleF, sf)

	loBmp.Save("TestUnicodes.Png", .Imaging.ImageFormat.Png)
	Run/N "mspaint" TestUnicodes.Png
Endwith
Retu

Function DrawStringW(toGfx, ;
		tcString, toFont As xfcFont, toBrush As xfcBrush, tnX, tnY ;
		, toFormat As xfcStringFormat)
	*********** tcString, toFont AS xfcFont, toBrush AS xfcBrush, toPoint AS xfcPointF ;
	, toFormat AS xfcStringFormat
	*********** tcString, toFont AS xfcFont, toBrush AS xfcBrush, toRectangle AS xfcRectangleF ;
	, toFormat AS xfcStringFormat

	Local lqLayoutRect
	Local lnWidth, lnHeight, loPoint As xfcPointF, loRect As xfcRectangleF
	Local lhFormat
	Store 0 To lnWidth, lnHeight
	Store Null To loPoint, loRect
	m.lqLayoutRect = 0h00
	** Handle overload parameters
	Do Case
		Case Vartype(tnX) = "N"
		Case Vartype(tnX) = "O" And Inlist(tnX.BaseName,"Point","PointF")
			m.loPoint = m.tnX
			m.toFormat = m.tnY
			m.loPoint.GetExtent(@tnX, @tnY)

		Case Vartype(tnX) = "O" And Inlist(tnX.BaseName,"Rectangle","RectangleF")
			m.loRect = m.tnX
			m.toFormat = m.tnY
			m.loRect.GetExtent(@tnX, @tnY, @lnWidth, @lnHeight)
	Endcase

	** Optional parameter
	** The C++ classes show this parameter as NULL if not specified
	If Vartype(m.toFormat) = "O"
		m.lhFormat = m.toFormat.Handle
	Else
		m.lhFormat = 0
	Endif

	m.lqLayoutRect = BinToC(m.tnX,"F")+BinToC(m.tnY,"F")+;
		BINTOC(m.lnWidth,"F")+BinToC(m.lnHeight,"F")

	=xfcGdipDrawString(toGfx.Handle, m.tcString+0h00, Lenc(tcString)/2, ;
		m.toFont.Handle, @lqLayoutRect, m.lhFormat, m.toBrush.Handle)
Endfunc


arabic.txt can be replaced by any unicode universal language.for occidental strings use only DrawString syntax.
arabic.txt can be replaced by any unicode universal language.for occidental strings use only DrawString syntax.

arabic.txt can be replaced by any unicode universal language.for occidental strings use only DrawString syntax.

Click on code to select [then copy] -click outside to deselect

                  
*3* created on Saturday 18 of february 2017
*this code asks on a folder images (jpg) and gather them in a cursor
*-then apply some effects on each image on  imgcanvas on a form
*rightclick on ny image to save it on capture folder created for this purpose.
*using paths and ARGB for setting transparency
*the code asks to point to gdiplus class.

Publi m.yrep0
m.yrep0=Addbs(Justpath(Sys(16,1)))
Set Defa To (yrep0)
If !Directory(m.yrep0+"captures")
	Md (m.yrep0+"captures")
Endi

Set Classlib To Locfile("gdiplusX.vcx","vcx")
Publi yform
yform=Newobject("yimg_effect")
Release Classlib gdiplusx
yform.Show
Read Events
Retu
*
Define Class yimg_effect As Form
	Height = 474
	Width = 729
	ShowWindow = 2
	AutoCenter = .T.
	Caption = "Glace effect on a form-gdiplusX- Rightclick to save image."
	ext = "JPG"
	Name = "Form1"

	Add Object image1 As Image With ;
		Anchor = 15, ;
		Picture = "d:\ymedia\fonds_ecran\oasis1024.jpg", ;
		Stretch = 2, ;
		Height = 491, ;
		Left = 0, ;
		Top = -11, ;
		Width = 732, ;
		Name = "Image1"

	Add Object imgcanvas1 As imgcanvas With ;
		Anchor = 15, ;
		Height = 372, ;
		Left = 60, ;
		Top = 24, ;
		Width = 588, ;
		rendermode = 4, ;
		Name = "Imgcanvas1"

	Add Object command1 As CommandButton With ;
		Top = 436, ;
		Left = 348, ;
		Height = 36, ;
		Width = 72, ;
		Anchor = 260, ;
		Caption = "Switch >", ;
		MousePointer = 15, ;
		Name = "Command1"

	Procedure getpath
		Lparameters rc,r,nCurvetype
		If Empty(nCurvetype)
			nCurvetype = 0
		Endif
		* nCurvetype - 0 full curve, 1 top only, 2 bottom only
		Local x,Y,w,h,xpath,rx
		x = rc.x
		Y = rc.Y
		w = rc.Width
		h = rc.Height
		rx = r
		ry=r
		Do Case
			Case nCurvetype = 1
				* top only
				rx = 1
			Case nCurvetype = 2
				* bottom only
				ry = 1
		Endcase

		With _Screen.System.Drawing
			xpath = .Drawing2D.GraphicsPath.New()
			xpath.AddArc(x, Y, ry, ry, 180, 90)			&& Upper left corner
			xpath.AddArc(x+w - ry, Y, ry, ry, 270, 90)		&&Upper right corner
			xpath.AddArc(x+w - rx, Y+h - rx, rx, rx, 0, 90)	&&Lower right corner
			xpath.AddArc(x, Y+h - rx, rx, rx, 90, 90)		&&Lower left corner
			xpath.CloseFigure()
		Endwith
		Return xpath
	Endproc

	Procedure Load
		Declare Integer Sleep In kernel32 Integer
		Publi yrep
		yrep=Addbs(Getdir())
		gnbre=Adir(gabase,yrep+"*.jpg")
		Create Cursor ycurs (yimage c(150))
		For i=1 To gnbre
			Insert Into ycurs Values (yrep+gabase(i,1))
		Endfor
		*brow
		Locate
	Endproc

	Procedure Init
		Sele ycurs
		Thisform.image1.Picture=yimage
	Endproc

	Procedure Destroy
		m.yrep=Null
		Release m.yrep
		m.yrep0=Null
		Release m.yrep0
		Clea Events
	Endproc


	Procedure imgcanvas1.beforedraw
		Local loPen As xfcPen
Local loGfx As xfcGraphics
loGfx=This.ogfx

Local loGfx As xfcGraphics
loGfx = This.ogfx
With _Screen.System.Drawing
	loGfx.Clear(.Color.Transparent)
	loGfx.SmoothingMode = .Drawing2D.SmoothingMode.AntiAlias

	*Applying filter with random colors
	Local loPathz As xfcGraphicsPath
	loRect1 = .Rectangle.new(5,5,This.Width-12,This.Height-12)
	path1 = Thisform.GetPath(loRect1, 30)
	loPen1 = .Pen.new(.Color.yellow,6)
	loGfx.DrawPath(loPen1,path1)
	loPathz = .Drawing2D.GraphicsPath.new(path1)
	Local loPathGradBrushz As xfcPathGradientBrush
	loPathGradBrushz = .Drawing2D.PathGradientBrush.new(loPathz)
	Rand(-1)
	loPathGradBrushz.CenterColor = .Color.fromRGB(255*Rand(),255*Rand(),255*Rand())

	Rand(-1)
	loPathGradBrushz.SurroundColors[1] =  .Color.fromARGB(180,255*Rand(),255*Rand(),255*Rand())
	loGfx.FillPath(loPathGradBrushz, loPathz)
    local x,r
	x=255
	r=This.Width/2
	loPen=.Pen.new(.Color.fromRGB(x),3)
	Local loPath As xfcGraphicsPath,loRect as xfcRectangle
	loPath = .Drawing2D.GraphicsPath.new()
	loRect=loRect1

	loPath.AddRectangle(loRect)

	Local loPathGradBrush As xfcPathGradientBrush
	loPathGradBrush = .Drawing2D.PathGradientBrush.new(loPath)


	loPathGradBrush.CenterColor = .Color.fromRGB(255*Rand(),255*Rand(),255*Rand())

	loPathGradBrush.SurroundColors[1] =  .Color.fromARGB(80,255*Rand(),255*Rand(),255*Rand())
	loGfx.FillPath(loPathGradBrush, loPath)

	loGfx.DrawPath(loPen1,path1)
Endwith
	Endproc

	Procedure imgcanvas1.RightClick
		Local x,Y,w,h
		With Thisform
			x=.Left+Sysmetric(3)
			Y=.Top++Sysmetric(9)+Sysmetric(4)+1
			w=.Width
			h=.command1.Top-2
		Endwith

		Local m.ext
		m.ext=Thisform.ext
		Try
			Local loCaptureBmp As xfcBitmap
			With _Screen.System.Drawing
				Local loCapture As xfcBitmap
				*LPARAMETERS tHWnd, tiX, tiY, tiWidth, tiHeight, [tlEnsureVisible]
				loCapture = .Bitmap.Fromscreen(0,x,Y,w,h) &&capture zone desktop (hwnd=0)
				Sleep(500)

				Local m.xx,m.lcdest
				m.xx="capture_"+Ttoc(Datetime())
				m.xx=Strtran(m.xx,"/","_")
				m.xx=Strtran(m.xx,":","_")
				m.xx=Strtran(m.xx,";","_")
				m.lcdest=m.yrep0+"captures\"+m.xx+"."+m.ext
				Do Case
					Case Upper(Thisform.ext)=="PNG"
						loCapture.Save(m.lcdest,.imaging.imageformat.PNG)
					Case Upper(Thisform.ext)=="JPG"
						loCapture.Save(m.lcdest,.imaging.imageformat.JPEG)
					Case Upper(Thisform.ext)=="BMP"
						loCapture.Save(m.lcdest,.imaging.imageformat.BMP)
					Case Upper(Thisform.ext)=="GIF"
						loCapture.Save(m.lcdest,.imaging.imageformat.GIF)
				Endcase
				Wait Window m.lcdest+" saved!" Timeout 3
			Endwith
		Catch
		Endtry
	Endproc

	Procedure command1.Click
		Sele ycurs
		If Eof()
			Locate
		Else
			Skip
		Endi
		Thisform.image1.Picture=yimage
		Thisform.imgcanvas1.Draw
	Endproc

	Procedure command1.Init
		This.Caption=""
		This.Picture=Home()+"graphics\icons\misc\misc05.ico"
	Endproc

Enddefine
*
*-- EndDefine: yimg_effect


A gdiplusX animated sample with many objects - drawStringW
A gdiplusX animated sample with many objects - drawStringW
A gdiplusX animated sample with many objects - drawStringW
A gdiplusX animated sample with many objects - drawStringW
 
Important:All Codes above are tested on VFP9SP2  & windows 10 pro.

To be informed of the latest articles, subscribe:
Comment on this post