Erase test.png
Declare Integer GdipDrawString In GDIPlus.Dll Long graphics,String Str,Long Length,Long thefont,String @layoutRect,Long StringFormat,Long brush
Declare Integer GdipCreateStringFormat In GDIPlus.Dll Integer formatAttributes,Integer Language,Integer @nFormat
Declare Integer GdipDeleteStringFormat In GDIPlus.Dll Long nFormat
Declare Integer GdipCreateFont In GDIPlus.Dll Integer fontFamily,Single emSize,Integer fntstyle,Integer unit,Integer @fnt
Declare Integer GdipDeleteFont In GDIPlus.Dll Integer fnt
Declare Integer GdipCreateSolidFill In GDIPlus.Dll Integer ARGBcolor,Integer @brush
Declare Integer GdipDeleteGraphics In GDIPlus.Dll Integer graphics
Declare Integer GdipDeleteBrush In GDIPlus.Dll Integer brush
Declare Integer GdipCreateFontFamilyFromName In GDIPlus.Dll String familyname,Integer FontCollection,Integer @FontFamily
Declare Integer GdipDeleteFontFamily In GDIPlus.Dll Integer FontFamily
Declare Integer GdipCreateFromHWND In GDIPlus.Dll Integer hWind,Integer @graphics
Declare Integer MultiByteToWideChar In kernel32 Long iCodePage,Long dwFlags,String @ lpStr,Long iMultiByte,String @ lpWideStr,Long iWideChar
Declare Integer GdipLoadImageFromFile In GDIPlus.Dll String wFilename,Integer @nImage
Declare Integer GdipSaveImageToFile In GDIPlus.Dll Integer nImage,String wFilename,String qEncoder,Integer nEncoderParamsPtr
Declare Integer GdipGetImageGraphicsContext In GDIPlus.Dll Integer nImage,Integer @ nGraphics
Declare Integer GdipCreateHatchBrush In GDIPlus.Dll Integer hatchstyle,Integer ForeCol,Integer BackCol,Integer @brush
Declare Integer GdipGetImageHeight In GDIPlus Integer img,Integer @ imgheight
Declare Integer GdipGetImageWidth In GDIPlus Integer img,Integer @ imgwidth
Declare Integer GdipDisposeImage In GDIPlus.Dll Long nativeImage
graphics=0
nimage=0
File_Name='c:\D.PNG' &&原图(此处可以是BMP,JPG,GIF,TIF,PNG,ICO格式的文件)
GdipLoadImageFromFile(Strconv(File_Name + Chr(0),5),@nimage)
*********开始写绿色的100**********
lcText='100'
lnLen = 2 * (Len(lcText) + 1)
lcWideStr = Replicate(Chr(0),lnLen)
MultiByteToWideChar(0,0,@lcText,Len(lcText),@lcWideStr,lnLen)
tcText=lcWideStr
lcFontName='黑体'&&字体名称,必须是已注册的字体
lcFontName=Strconv(lcFontName+Chr(0),5)
lnFontFamily=0
GdipCreateFontFamilyFromName(lcFontName,0,@lnFontFamily)
lnFont=0
lnFontStyle=1&&字体类型,0默认,1加粗,2倾斜3=1+2加粗倾斜 4U 8 S
tnSize=10&&字体大小
GdipCreateFont(lnFontFamily,tnSize,lnFontStyle,3,@lnFont)
lnFormatHandle = 0
thAlignment=0&&对其格式 居左
GdipCreateStringFormat(0,0,@lnFormatHandle )
nAlign = lnFormatHandle
brush=0
ucolor1=Rgb(0,255,0)&&字体颜色
aphpi=255&&透明度
lnColor1 = CToBin(Chr(aphpi)+Left(BinToC(uColor1,'4rs'),3),'4s')
ucolor2=Rgb(0,255,0)&&字体颜色
aphpi=255&&透明度
lnColor2 = CToBin(Chr(aphpi)+Left(BinToC(uColor2,'4rs'),3),'4s')
GdipCreateHatchBrush(11,lnColor1,lnColor2,@brush)&&建立纹理刷子
x=17&&绘制文字的左上角坐标
Y=28
w=0
h=0
GdipGetImageWidth(nImage,@w)
GdipGetImageHeight(nImage,@h)
lcRectangleF=BinToC(x,'F')+BinToC(Y,'F')+BinToC(w,'F')+BinToC(h,'F')
GdipGetImageGraphicsContext (nImage,@Graphics)
GdipDrawString(Graphics,tcText,Len(lcText),lnFont,@lcRectangleF,0,brush)
*********写绿色的100结束**********
GdipDeleteFontFamily(lnFontFamily)
GdipDeleteFont(lnFont)
GdipDeleteBrush(brush)
GdipDeleteGraphics(Graphics)
GdipDeleteStringFormat(lnFormatHandle)
*********开始写红色的200**********
lcText='200'
lnLen = 2 * (Len(lcText) + 1)
lcWideStr = Replicate(Chr(0),lnLen)
MultiByteToWideChar(0,0,@lcText,Len(lcText),@lcWideStr,lnLen)
tcText=lcWideStr
lcFontName='黑体'&&字体名称,必须是已注册的字体
lcFontName=Strconv(lcFontName+Chr(0),5)
lnFontFamily=0
GdipCreateFontFamilyFromName(lcFontName,0,@lnFontFamily)
lnFont=0
lnFontStyle=1&&字体类型,0默认,1加粗,2倾斜3=1+2加粗倾斜 4U 8 S
tnSize=10&&字体大小
GdipCreateFont(lnFontFamily,tnSize,lnFontStyle,3,@lnFont)
lnFormatHandle = 0
thAlignment=0&&对其格式 居左
GdipCreateStringFormat(0,0,@lnFormatHandle )
nAlign = lnFormatHandle
brush=0
ucolor1=Rgb(255,0,0)&&字体颜色
aphpi=255&&透明度
lnColor1 = CToBin(Chr(aphpi)+Left(BinToC(uColor1,'4rs'),3),'4s')
ucolor2=Rgb(255,0,0)&&字体颜色
aphpi=255&&透明度
lnColor2 = CToBin(Chr(aphpi)+Left(BinToC(uColor2,'4rs'),3),'4s')
GdipCreateHatchBrush(11,lnColor1,lnColor2,@brush)&&建立纹理刷子
x=17&&绘制文字的左上角坐标
Y=45
w=0
h=0
GdipGetImageWidth(nImage,@w)
GdipGetImageHeight(nImage,@h)
lcRectangleF=BinToC(x,'F')+BinToC(Y,'F')+BinToC(w,'F')+BinToC(h,'F')
GdipGetImageGraphicsContext (nImage,@Graphics)
GdipDrawString(Graphics,tcText,Len(lcText),lnFont,@lcRectangleF,0,brush)
*********写红色的200结束**********
lcEncoder=0h06F47C55041AD3119A730000F81EF32E &&PNG
*lcEncoder=0h00F47C55041AD3119A730000F81EF32E &&BMP
*lcEncoder=0h01F47C55041AD3119A730000F81EF32E &&JPG
*lcEncoder=0h02F47C55041AD3119A730000F81EF32E &&GIF
*lcEncoder=0h05F47C55041AD3119A730000F81EF32E &&TIF
*lcEncoder=0h06F47C55041AD3119A730000F81EF32E &&PNG
GdipSaveImageToFile (nImage,Strconv("c:\test.png",5) + Chr(0),lcEncoder,0)
GdipDeleteFontFamily(lnFontFamily)
GdipDeleteFont(lnFont)
GdipDisposeImage(nImage)
GdipDeleteBrush(brush)
GdipDeleteGraphics(Graphics)
GdipDeleteStringFormat(lnFormatHandle)