[quote name='klem4' date='15.05.2007 11:17' post='102164']
А зачем ты рисуешь на Image ? И что ты там рисуешь ? Если график функции, то может лучше использовать TChart ? Посмотри тогда вот эту тему:
Синхронизация TChartРисую график параметры которого задаються параметрически. Как узнать левую правую нижнюю и верхнюю границу графика. Сделано пока коряво но все же работает.Вот код.
Код
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, Spin;
type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
SpinEdit3: TSpinEdit;
SpinEdit4: TSpinEdit;
cd1: TColorDialog;
Label5: TLabel;
Edit1: TEdit;
Button3: TButton;
Button4: TButton;
ScrollBox1: TScrollBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
procedure SpinEdit3Change(Sender: TObject);
procedure SpinEdit4Change(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Wx,Wy,W1,W2: real;
x1,y1,x2,y2:real;
x,y,t,h:real;
I1,J1,I2,J2,n,j:integer;
m:real;
implementation
{$R *.dfm}
{------------------------------------------------------------------------------}
function Fx(t:real):real;
begin
Fx:=Sin(Wx*t+W1)
end;
{------------------------------------------------------------------------------}
function Fy(t:real):real;
begin
Fy:=Sin(Wy*t+W2)
end;
{------------------------------------------------------------------------------}
function II(x:real):integer;
begin
II:=I1+Trunc((x-x1)*(I2-I1)/(x2-x1))
end;
{------------------------------------------------------------------------------}
function JJ(x:real):integer;
begin
JJ:=J1+Trunc((y-y1)*(J2-J1)/(y2-y1))
end;
{------------------------------------------------------------------------------}
procedure DrawGraphic(Wx:real;Wy:real;W1:real;W2:real);
var i:integer;
t:real;
begin
//Масштаб!
m:=strtofloat(form1.Edit1.Text);
x1:=3; y1:=3;
x2:=0; y2:=0;
x1:=x1-m; y1:=y1-m;
x2:=x2+m; y2:=y2+m;
if m<1 then begin
Form1.Image1.Height:=1000;
Form1.Image1.Width:= 1000;
form1.Image1.Picture.Bitmap.Height:=1000;
form1.Image1.Picture.Bitmap.Width:=form1.Image1.Picture.Bitmap.Width+1000;
end
else if (m>1)or(m=1) then
begin
Form1.Image1.Height:=5000;
Form1.Image1.Width:=5000;
form1.Image1.Picture.Bitmap.Height:=5000;
form1.Image1.Picture.Bitmap.Width:=5000;
end
else if (m>2) then
begin
Form1.Image1.Height:=10000;
Form1.Image1.Width:=10000;
form1.Image1.Picture.Bitmap.Height:=10000;
form1.Image1.Picture.Bitmap.Width:=10000;
end;
with Form1.Image1,Form1.Image1.Canvas do
begin
Rectangle(0,0,Width,Height);
t:=0;x:=Fx(t);y:=Fy(t);
MoveTo(II(x),JJ(y));
for i:=1 to 5*n do
begin
t:=t+h;x:=Fx(t);
y:=Fy(t);
LineTo(II(x),JJ(y))
end;
end
end;
{------------------------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.edit1.Text:=floattostr(0.1);
n:=350;
//Начальный масштаб!
x1:=3; y1:=3;
x2:=0; y2:=0;
I1:=1;
J1:=1;
I2:=Image1.Width;
J2:=Image1.Height;
h:=2*Pi/n;
Wx:=2; Wy:=4;W1:=6;W2:=3;
DrawGraphic(Wx,Wy,w1,w2);
end;
{------------------------------------------------------------------------------}
procedure TForm1.Button1Click(Sender: TObject);
begin
if Cd1.Execute=true then
Form1.Image1.Canvas.Pen.Color:=cd1.Color;
DrawGraphic(Wx,wy,w1,w2);
end;
{------------------------------------------------------------------------------}
procedure TForm1.Button2Click(Sender: TObject);
begin
if Cd1.Execute=true then
Form1.Image1.Canvas.Brush.Color:=cd1.Color;
DrawGraphic(Wx,wy,w1,w2);
end;
{------------------------------------------------------------------------------}
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
Wx:=SpinEdit1.Value;
DrawGraphic(Wx,wy,w1,w2);
end;
{------------------------------------------------------------------------------}
procedure TForm1.SpinEdit2Change(Sender: TObject);
begin
Wy:=SpinEdit2.Value;
DrawGraphic(Wx,wy,w1,w2)
end;
{------------------------------------------------------------------------------}
procedure TForm1.SpinEdit3Change(Sender: TObject);
begin
W1:=SpinEdit3.Value;
DrawGraphic(Wx,wy,w1,w2)
end;
{------------------------------------------------------------------------------}
procedure TForm1.SpinEdit4Change(Sender: TObject);
begin
W2:=SpinEdit4.Value;
DrawGraphic(Wx,wy,w1,w2)
end;
{------------------------------------------------------------------------------}
function XX (I: integer): real;
begin
XX := X1 + (I-I1) * (X2-X1) / (I2-I1)
end;
function YY (J: integer): real;
begin
YY := Y1 + (J2-J) * (Y2-Y1) / (J2-J1)
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
image1.Hint:='x:'+inttostr(x)+' '+ 'y:'+inttostr(y);
application.ActivateHint(mouse.CursorPos);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
DrawGraphic(Wx,wy,w1,w2)
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
halt
end;
end.