实现TCHART+上面透明图片飘动效果delphi
tchart也用GDI+功能实现,实现功能包括,x轴坐标,y轴坐标显示,外框实线,内框虚线,并实时画曲线
波动率,并有TCHART背景图片
实现方法是:
uses GDIPOBJ, GDIPAPI;
以下过程均在FormPaint中实现
var g:tgpGraphics;
Image,Thumbnail: TGPImage;
bit1,bit2:tbitmap;
m,n:integer;
t:integer;
正确的做法是要用 TBitmap 来缓冲:
1、给 TBitmap1 载入你的图片;
bit1:=tbitmap.Create;
bit1.LoadFromFile('C:\Documents and Settings\king\My Documents\My Pictures\winter_1024_1_.bmp');
2、在带有图片的 TBitmap1 上画格;
x轴坐标,y轴坐标显示,外框实线,内框虚线,
3、把 TBitmap1 上画好的东西复制到 TBitmap2;
bit2.Assign(bit1);
bit2.Canvas.Pen.Color:=clred;
bit2.Canvas.Pen.Style:=pssolid;
4、在 TBitmap2 上画你的实时曲线;
for t:=0 to arrj-2 do //画曲线
begin
if (yarr[t+1]<>'') and (yarr[t]<>'') then//yarr为实时获取的数据数组
begin
//540为500格子的高度+从40点画起
bit2.Canvas.MoveTo(t*20+40,strtoint(floattostr(int(540-strtofloat(yarr[t])*(500/(strtofloat(yarr [maxy])*2))))));
bit2.Canvas.LineTo((t+1)*20+40,strtoint(floattostr(int(540-strtofloat(yarr[t+1])*(500/(strtofloat (yarr[maxy])*2))))));
end;
end;
5、把 TBitmap2 上的图型复制到目的地.
//将bit2画好的图片放到image1上
BitBlt(Form1.image1.Canvas.Handle, 0, 0, bit2.Width, bit2.Height, bit2.Canvas.Handle, 0, 0, SRCCopy);
6、在图片上面画飘动的透明图片
g:=tgpgraphics.Create(image1.Canvas.Handle);
//////画png透明移动图片
Image:= TGPImage.Create('C:\Documents and Settings\king\桌面\未标题-1.png');
Thumbnail := image.GetThumbnailImage(200, 150, nil, nil);
g.DrawImage(Thumbnail, i, 10, Thumbnail.GetWidth, Thumbnail.GetHeight);
Image.Free;
Thumbnail.Free;
bit1.Free;
bit2.Free;
7、timer1事件,另透明图片移动
i:=i+2;
if i>800 then i:=-150 ;
repaint;
8、timer2事件主要实现取波动数据,并画波动率,在x轴标点实现时间的变化
g1 := TGPGraphics.Create(image1.Canvas.Handle);
p3 := TGPPen.Create(MakeColor(255,0,0), 2);
f3:=TGPFont.Create('宋体', 9);
solidbrush3:=TGPSolidBrush.Create(aclblack);
if (time=3) or (time=0) then
begin
g1.DrawString(formatdatetime('hh-mm-ss',now),-1,f3,makepoint(strtofloat(inttostr(j- 30)),550.0),solidbrush3);
time:=0;
xarr[arri]:=formatdatetime('hh-mm-ss',now);
end;
9、FormCreate事件中实现避免画面抖动
i:=-150;
self.DoubleBuffered:=true;