以下内容是使用Delphi 5完成的,供您参考。 我在将一张图像的内容复制到另一张图像时遇到一个小问题。
第一个图像包含我从文本文件中加载的绘制文本。请参阅下面的代码。
function TMainForm.GetText(Img: TImage; v: string; dosize: boolean): boolean;
var f:extended;
p:timage;
fl: textfile;
s, t:string;
crect:Trect;
ds: Longint;
ws: widestring;
begin
v := GetImgFile(v);
if not fileexists(v) then
result := false
else try
p := img;
dosize := dosize and img.Stretch;
AssignFile(fl, v);
reset(fl);
crect := p.ClientRect;
p.canvas.Font := Refline.font;
p.canvas.Brush.Style := bsClear;
p.canvas.Brush.Color := clBtnFace;
p.Canvas.Font.Size := 8;
p.canvas.FillRect(crect);
ds := DT_NOPREFIX or DT_EXPANDTABS or DT_WORDBREAK;
while not eof(fl) do begin
Readln(fl, s);
t := t + s;
end;
ws := StrToWide(t);
DrawTextW(p.canvas.Handle, pwidechar(ws), length(ws), crect, ds);
result := true;
except
result := false;
end;
end;
行 v := GetImg File 也接收文本文件的完整路径。 img 是我放置在表单上的图像。 然后通过使用 DrawTextW 我可以在该图像中绘制文本。 在此之前,我已经使用以下代码为 timage 准备了一个 TRect。
myimage.tag := 1;
myimage.canvas.Brush.Color := clBtnFace;
myimage.canvas.Brush.Style := bsClear;
myimage.Canvas.Font := refline.font;
crect2 := Rect(myimage.left,myimage.top,myimage.left + myimage.width,myimage.top + myimage.Height);
myimage.canvas.FillRect(crect2);
myimage.visible := GetText(MyImage, copy(ws, 4, length(ws)), copy(ws, 2, 1) = 'p');
这部分有效,这在图像中显示了我的文本。 现在我有另一个名为 myimage2 的 timage,我想将绘制的文本复制到该 timage 中。 我在复制时遇到问题。
我尝试使用简单的方法:myimage2.picture := myimage.picture。 我尝试将图像从 myimage 分配给 myimage2。 我尝试的最后一件事是 copyrect 函数。
myimage2.Canvas.CopyRect(crect3,myimage.Canvas,crect2);
其中 crect2 是来自 myimage 的矩形,而 crect3 是来自 myimage2 的矩形。
上述所有 3 种可能性都未能将绘制的文本复制到第二张图像。
我显然在这里做错了什么,这可能是非常小的事情,但我没有看到问题。
我做错了什么?
找到解决方案!
它有助于确保 myimage2.visible 设置为 true... 然后使用
myimage2.picture := myimage.picture;
绘制的文字被复制...