D
danie
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我写的一个程序,从数据库中查询数据,然后(用image)画成曲线图!在第一次查询(以实验名为查询变量)时,一切都是好的
但查询另一个实验名时,也就是数据不同时,他就出现曲线与数据不一样的状况!但查询第一次的实验名时,一切又是对
的.后来改用paintbox画图,一切ok ,但是我需要对图形进行压缩.
问题1;paintbox 怎么进行压缩.每个像素我度有用,我是一个像素画一个数据;
问题2:如果用image我能解决压缩的问题,但又出现前述的问题,我快风了!!!
//下面这个程序用image画图,如果改用paintbox,将多线程中定义改一下即可!
//由于程序的需要,画图部分我采用多线程来实现
unit thds;
interface
uses
WinProcs,Classes,Graphics,ExtCtrls;
const mynum=600;
type
//数组
Tsz=record
x:array of integer; //对应X坐标
y:array of real; //对应Y坐标
szcount:array of integer;
end;
TmyPoint=array of Tpoint;
//**********************
TPaintboxThds = class(TThread)
private
Fbox:TPaintbox;
Fsz:Tsz;
Fpoint:Tmypoint;
Function adjust(Fself,max,min:Real;bz:integer):integer;//bz为标准
procedure Mydraw;
protected
procedure Execute; override;
public
constructor Create(Suspended:Boolean;box:TPaintbox;Sz:Tsz;int:integer);
end;
implementation
procedure Tszclear(sz:Tsz);
var i:integer;
begin
for i:=0 to high(sz.x) do
begin
sz.x:=i;
sz.y:=0;
sz.szcount:=0;
end;
end;
//数据在坐标上的调整
Function TPaintboxThds.adjust(Fself,max,min:Real;bz:integer):integer;//bz为标准
begin
Adjust:=trunc((max-Fself)*bz/(max-min))+15;
end;
procedure TPaintboxThds.Mydraw;
var i:integer;
begin
for i:=0 to High(Fpoint) do
begin
Fpoint.x:=Fsz.x;
Fpoint.y:=adjust(Fsz.y,1,0,340);
end;
with Fbox do
begin
Refresh;
canvas.pen.color:=clred;
Canvas.Polyline(Fpoint);
end;
end;
constructor TPaintboxThds.Create(Suspended:Boolean;box:TPaintbox;Sz:Tsz;int:integer);
begin
inherited Create(Suspended);
Fbox:=box;
Fsz:=sz;
SetLength(Fpoint,int);
FreeOnTerminate:=True;
end;
procedure TPaintboxThds.Execute;
begin
Synchronize(mydraw);
end;
end.
//实现部分
unit lssj;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Db, DBTables, Grids, DBGrids,thds, Buttons;
.....
var
Form2: TForm2;
Fsz2:Tsz1;
Flabel : array[1..8] of TLabel;
implementation
{$R *.DFM}
//查询画图
procedure TForm2.Button1Click(Sender: TObject);
var newbmp:Tbitmap;
i,j:integer;
begin
with form2.Query1 do
begin
Active:=false;
ParamByName('Name').value:=form2.Edit1.Text;
active:=True;
end;
//**************************画图**************************//
if query1.RecordCount>0 then
begin
image1.Enabled:=True;
//设定数组长度
setlength(Fsz2.x,query1.RecordCount);
setlength(Fsz2.Y,query1.RecordCount);
setlength(Fsz2.SZCOUNT,query1.RecordCount);
edit2.Text:=inttostr(query1.RecordCount);
Tszclear(Fsz2);
query1.First;
for i:=0 to High(Fsz2.x) do
begin
Fsz2.y:=strtofloat(query1.FieldByName('Fxgd').value);
Fsz2.x:=i;
Fsz2.szcount:=i+1;
query1.Next;
end;
if query1.RecordCount>600 then
begin
FORM2.image1.Width:=Query1.RecordCount;
Timagethds.Create(false,image1,Fsz2,Query1.RecordCount);
end
else
begin
image1.Width:=600;
Timagethds.Create(false,image1,Fsz2,Query1.RecordCount);
end;
end
else
begin
newbmp:= TBitmap.Create;
newbmp.Width:=strtoint(edit2.text);
newbmp.Height:=image1.Height;
image1.Canvas.Draw(0,0,newbmp);
newbmp.free;
image1.Enabled:=false;
edit2.Text:='0';
end;
end;
//退出
procedure TForm2.BitBtn1Click(Sender: TObject);
var j:integer;
newbmp:Tbitmap;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=strtoint(edit2.text);
newbmp.Height:=image1.Height;
image1.Canvas.Draw(0,0,newbmp);
newbmp.free;
edit2.Text:='0';
query1.Active:=false;
close;
end;
//图形压缩
procedure TForm2.Button2Click(Sender: TObject);
var j,jz:integer;//
begin
if query1.RecordCount>600 then
begin
image1.Width:=600;
image1.Refresh;
end;
end;
thanks!!!!
但查询另一个实验名时,也就是数据不同时,他就出现曲线与数据不一样的状况!但查询第一次的实验名时,一切又是对
的.后来改用paintbox画图,一切ok ,但是我需要对图形进行压缩.
问题1;paintbox 怎么进行压缩.每个像素我度有用,我是一个像素画一个数据;
问题2:如果用image我能解决压缩的问题,但又出现前述的问题,我快风了!!!
//下面这个程序用image画图,如果改用paintbox,将多线程中定义改一下即可!
//由于程序的需要,画图部分我采用多线程来实现
unit thds;
interface
uses
WinProcs,Classes,Graphics,ExtCtrls;
const mynum=600;
type
//数组
Tsz=record
x:array of integer; //对应X坐标
y:array of real; //对应Y坐标
szcount:array of integer;
end;
TmyPoint=array of Tpoint;
//**********************
TPaintboxThds = class(TThread)
private
Fbox:TPaintbox;
Fsz:Tsz;
Fpoint:Tmypoint;
Function adjust(Fself,max,min:Real;bz:integer):integer;//bz为标准
procedure Mydraw;
protected
procedure Execute; override;
public
constructor Create(Suspended:Boolean;box:TPaintbox;Sz:Tsz;int:integer);
end;
implementation
procedure Tszclear(sz:Tsz);
var i:integer;
begin
for i:=0 to high(sz.x) do
begin
sz.x:=i;
sz.y:=0;
sz.szcount:=0;
end;
end;
//数据在坐标上的调整
Function TPaintboxThds.adjust(Fself,max,min:Real;bz:integer):integer;//bz为标准
begin
Adjust:=trunc((max-Fself)*bz/(max-min))+15;
end;
procedure TPaintboxThds.Mydraw;
var i:integer;
begin
for i:=0 to High(Fpoint) do
begin
Fpoint.x:=Fsz.x;
Fpoint.y:=adjust(Fsz.y,1,0,340);
end;
with Fbox do
begin
Refresh;
canvas.pen.color:=clred;
Canvas.Polyline(Fpoint);
end;
end;
constructor TPaintboxThds.Create(Suspended:Boolean;box:TPaintbox;Sz:Tsz;int:integer);
begin
inherited Create(Suspended);
Fbox:=box;
Fsz:=sz;
SetLength(Fpoint,int);
FreeOnTerminate:=True;
end;
procedure TPaintboxThds.Execute;
begin
Synchronize(mydraw);
end;
end.
//实现部分
unit lssj;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Db, DBTables, Grids, DBGrids,thds, Buttons;
.....
var
Form2: TForm2;
Fsz2:Tsz1;
Flabel : array[1..8] of TLabel;
implementation
{$R *.DFM}
//查询画图
procedure TForm2.Button1Click(Sender: TObject);
var newbmp:Tbitmap;
i,j:integer;
begin
with form2.Query1 do
begin
Active:=false;
ParamByName('Name').value:=form2.Edit1.Text;
active:=True;
end;
//**************************画图**************************//
if query1.RecordCount>0 then
begin
image1.Enabled:=True;
//设定数组长度
setlength(Fsz2.x,query1.RecordCount);
setlength(Fsz2.Y,query1.RecordCount);
setlength(Fsz2.SZCOUNT,query1.RecordCount);
edit2.Text:=inttostr(query1.RecordCount);
Tszclear(Fsz2);
query1.First;
for i:=0 to High(Fsz2.x) do
begin
Fsz2.y:=strtofloat(query1.FieldByName('Fxgd').value);
Fsz2.x:=i;
Fsz2.szcount:=i+1;
query1.Next;
end;
if query1.RecordCount>600 then
begin
FORM2.image1.Width:=Query1.RecordCount;
Timagethds.Create(false,image1,Fsz2,Query1.RecordCount);
end
else
begin
image1.Width:=600;
Timagethds.Create(false,image1,Fsz2,Query1.RecordCount);
end;
end
else
begin
newbmp:= TBitmap.Create;
newbmp.Width:=strtoint(edit2.text);
newbmp.Height:=image1.Height;
image1.Canvas.Draw(0,0,newbmp);
newbmp.free;
image1.Enabled:=false;
edit2.Text:='0';
end;
end;
//退出
procedure TForm2.BitBtn1Click(Sender: TObject);
var j:integer;
newbmp:Tbitmap;
begin
newbmp:= TBitmap.Create;
newbmp.Width:=strtoint(edit2.text);
newbmp.Height:=image1.Height;
image1.Canvas.Draw(0,0,newbmp);
newbmp.free;
edit2.Text:='0';
query1.Active:=false;
close;
end;
//图形压缩
procedure TForm2.Button2Click(Sender: TObject);
var j,jz:integer;//
begin
if query1.RecordCount>600 then
begin
image1.Width:=600;
image1.Refresh;
end;
end;
thanks!!!!