我有个图象是32×32的,想用它来做FORM的背景图
可是FORM太大,图象太小
如何使的该图象能以重慢整个FORM的背景哪?
帮你UP一下,我不会
是啊!我本来想问的,关于如何获取图像的高度与宽度,关注
1、在Var部分加入以下说明:
TileImage:TImage;
2、编写Form1.OnCreate事件代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
TileImage:=TImage.Create(Self);
TileImage.Picture.LoadFromFile(bg_green.bmp);
end;
3、编写Form1.OnPaint事件代码:
procedure TForm1.FormPaint(Sender: TObject);
var
PWidth,PHeight,X,Y: Integer;
begin
PWidth := TileImage.Picture.Bitmap.Width;
PHeight := TileImage.Picture.Bitmap.Height;
X := 0;
while X < Form1.Width do begin
Y := 0;
while Y < Form1.Height do begin
Form1.Canvas.Draw(X, Y, TileImage.Picture.Bitmap);
Y := Y + PHeight;
end;
X := X + PWidth;
end;
end;
你需要把主窗体设置为:formStyle:=fsMDIForm;
procedure TMainFrm.DrawStretched;//拉伸
var
CR: TRect;
begin
GetWindowRect(ClientHandle, CR);
StretchBlt(FDrawDC, 0, 0, CR.Right, CR.Bottom,
imgMain.Picture.Bitmap.Canvas.Handle, 0, 0,
imgMain.Picture.Width, imgMain.Picture.Height, SRCCOPY);
end;
procedure TMainFrm.DrawCentered;//局中
var
CR: TRect;
begin
GetWindowRect(ClientHandle, CR);
with imgMain do
BitBlt(FDrawDC, ((CR.Right - CR.Left) - Picture.Width) div 2,
((CR.Bottom - CR.) - Picture.Height) div 2,
Picture.Graphic.Width, Picture.Graphic.Height,
Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;
procedure TMainFrm.DrawTiled;//平铺
var
Row, Col: Integer;
CR, IR: TRect;
NumRows, NumCols: INteger;
begin
GetWindowRect(ClientHandle, CR);
IR := imgMain.ClientRect;
NumRows := CR.Bottom div IR.Bottom;
NumCols := CR.Right div IR.Right;
with imgMain do
for Row :=0 to NumRows+1 do
for Col :=0 to NumCols+1 do
BitBlt(FDrawDC, Col*Picture.Width, Row*Picture.Height,
Picture.Width, Picture.Height,
Picture.Bitmap.Canvas.Handle, 0, 0, SRCCOPY);
end;
procedure TMainFrm.ClientWndProc(var Message: TMessage);
begin
case Message.Msg of
WM_EraseBKGnd:
begin
CallWindowProc(FoldClientProc, ClientHandle, Message.Msg,
Message.WParam, Message.LParam);
FDrawDC := TWMEraseBKGnd(Message).DC;
DrawStretched; //拉伸
//DrawCentered; //居中
//DrawTiled; //平铺
Message.Result := 1;
end;
WM_VSCROLL, WM_HSCROLL:
begin
Message.Result := CallWindowProc(FOldClientProc, CLientHandle,
Message.Msg, Message.WParam, Message.LParam);
InvalidateRect(ClientHandle, nil, True);
end;
else
Message.Result := CallWindowProc(FOldClientProc, CLientHandle,
Message.Msg, Message.WParam, Message.LParam);
end;
end;
procedure TMainFrm.FormCreate(Sender: TObject);
begin
FNewClientProc := MakeObjectInstance(ClientWndProc);
FOldClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
SetWindowLong(ClientHandle,GWL_WNDPROC,LongInt(FNewClientProc));
end;
var
pjpg:tjpegimage;
X,Y:INTEGER;
begin
X:=0;
Y:=0;
pjpg:=tjpegimage.Create;
pjpg.LoadFromFile(D:\1.jpg);
WHILE Y<IMAGE1.Height DO
BEGIN
WHILE X<IMAGE1.Width DO
BEGIN
IMAGE1.Canvas.Draw(X,Y,pjpg);
X:=X+pjpg.Width;
END;
X:=0;
Y:=Y+pjpg.Height;
END;
end;