D
dirk
Unregistered / Unconfirmed
GUEST, unregistred user!
帮别人忙,随便写个合成图片的小程序(代码在后面):<br>function LoadBJ(PicName: PChar): boolean; stdcall;<br>导入背景图<br>function LoadQJ(PicName: PChar;X,Y:integer): boolean; stdcall;<br>导入前景图,指定其显示在背景的位置<br>function LoadText(Text,FontName: PChar;X,Y:integer;FontColor:integer=0;FontSize:integer=9;<br> FontBold:boolean=false;FontItalic:boolean=false;FontUnderline:boolean=false): boolean; stdcall;<br>在背景上输出文字,指定位置和字体<br>function SavePic(NewPicName: PChar): boolean; stdcall;<br>保存合成图片<br><br>然后输出这几个函数<br>exports<br> LoadBJ,<br> LoadQJ,<br> LoadText,<br> SavePic;<br><br>在delphi中图片、文字完全可以合成,产生新的图片文件,但是在word中调用,只能把背景图保存出来,但前景图、文字却不能画到背景图上去,以下是word中的代码:<br><br>Option Explicit<br>Private Declare Function LoadBJ Lib "e:/SMG.dll" (ByVal PicName As String) As Boolean<br><br>Private Declare Function LoadQJ Lib "e:/SMG.dll" (ByVal PicName As String, X, Y As Integer) As Boolean<br><br>Private Declare Function LoadText Lib "e:/SMG.dll" (ByRef Text As String, ByVal FontName As String, X, Y As Integer, Optional FontColor As Integer = 0, Optional FontSize As Integer = 9, Optional FontBold As Boolean = False,Optional FontItalic As Boolean = False, Optional FontUnderline As Boolean = False) As Boolean<br><br>Private Declare Function SavePic Lib "e:/SMG.dll" (ByVal NewPicName As String) As Boolean<br><br>Private Sub CommandButton1_Click()<br> Call LoadBJ("e:/5.bmp")<br> Call LoadQJ("E:/6.bmp", 100, 100)<br> Call LoadText("嘿嘿嘿!123", "", 200, 200, 125, 18, True)<br> Call SavePic("e:/dass.bmp")<br><br><br>End Sub<br><br>在word中调用,.Canvas.Draw(X ,Y ,img_wz.Picture.Graphic );这句话根本就没有用,换成bitblt也不行,也不报错,但图像就是不输出到指定的场景上,我真是晕了,为什么会这样?后来我尝试了另一种方式,在dll中添加一个form,然后在form上放image,把form显示出来,一样的代码,在form上的一个button上执行,到是能把图像画到指定的场景上,这到底是为什么?<br><br>delphi做出来的标准动态库到底是不是真正的标准动态库?那为什么在其他的语言中调用会出现和delphi中调用运行的结果不同呢?<br><br>以下是delphi代码:<br><br>unit Lib;<br><br>interface<br><br>uses<br> SysUtils, Windows, Classes, ExtCtrls, Graphics, StdCtrls ;<br><br>function LoadBJ(PicName: PChar): boolean; stdcall;<br>function LoadQJ(PicName: PChar;X,Y:integer): boolean; stdcall;<br>function LoadText(Text,FontName: PChar;X,Y:integer;FontColor:integer=0;FontSize:integer=9;<br> FontBold:boolean=false;FontItalic:boolean=false;FontUnderline:boolean=false): boolean; stdcall;<br>function SavePic(NewPicName: PChar): boolean; stdcall;<br><br>implementation<br><br>var<br> img_bj: TImage;<br> img_wz: TImage;<br> img_qj: TImage;<br> Lbl: TLabel;<br><br>function LoadBJ(PicName: PChar): boolean; stdcall;<br>begin<br> img_bj.Free ;<br> img_bj:=TImage.Create(nil);<br> img_bj.AutoSize :=true;<br><br> img_bj.Picture.LoadFromFile(PicName);<br> Result :=true;<br>end;<br><br>function LoadQJ(PicName: PChar;X,Y:integer): boolean; stdcall;<br>begin<br> img_qj.Free ;<br> img_qj:= TImage.Create(nil);<br> img_qj.AutoSize :=true;<br><br> img_qj.Picture.LoadFromFile(PicName);<br> img_bj.Canvas.Draw(X ,Y ,img_qj.Picture.Graphic );<br><br> Result :=true;<br>end;<br><br>function LoadText(Text,FontName: PChar;X,Y:integer;FontColor:integer=0;FontSize:integer=9;<br> FontBold:boolean=false;FontItalic:boolean=false;FontUnderline:boolean=false): boolean; stdcall;<br>begin<br> Lbl.Font.Name :=FontName;<br> Lbl.Font.Size :=FontSize;<br> Lbl.Font.Color :=FontColor;<br> Lbl.Font.Style :=[];<br><br> if FontBold then Lbl.Font.Style :=Lbl.Font.Style +[fsBold];<br> if FontItalic then Lbl.Font.Style :=Lbl.Font.Style +[fsItalic];<br> if FontUnderline then Lbl.Font.Style :=Lbl.Font.Style +[fsUnderline];<br><br> Lbl.Caption :=Text;<br><br> img_wz.Width :=lbl.Width ;<br> img_wz.Height :=lbl.Height ;<br><br> img_wz.Canvas.Font.Name :=FontName;<br> img_wz.Canvas.Font.Size :=FontSize;<br> img_wz.Canvas.Font.Color :=FontColor;<br> img_wz.Canvas.Font.Style :=[];<br><br> if FontBold then img_wz.Canvas.Font.Style :=img_wz.Canvas.Font.Style +[fsBold];<br> if FontItalic then img_wz.Canvas.Font.Style :=img_wz.Canvas.Font.Style +[fsItalic];<br> if FontUnderline then img_wz.Canvas.Font.Style :=img_wz.Canvas.Font.Style +[fsUnderline];<br><br> img_wz.Canvas.TextOut(0,0,Text);<br><br> img_bj.Canvas.Draw(X ,Y ,img_wz.Picture.Graphic );<br><br> Result :=true;<br>end;<br><br>function SavePic(NewPicName: PChar): boolean; stdcall;<br>begin<br> img_bj.Picture.SaveToFile(NewPicName);<br> Result :=true;<br>end;<br><br>initialization<br> img_bj:=TImage.Create(nil);<br> img_bj.AutoSize :=true;<br><br> img_qj:= TImage.Create(nil);<br> img_qj.AutoSize :=true;<br><br> img_wz:=TImage.Create(nil);<br> img_wz.AutoSize :=false;<br> img_wz.Transparent :=true;<br><br> Lbl:= TLabel.Create(nil);<br> Lbl.AutoSize :=true;<br> Lbl.Font.Name :='宋体';<br> Lbl.Font.Size :=9;<br> Lbl.Font.Color :=0;<br> Lbl.Font.Style :=[];<br><br>finalization<br> img_bj.Free ;<br> img_qj.Free ;<br> img_wz.Free ;<br> Lbl.Free ;<br><br>end.<br><br>