不知道我的程序为什么不行!
开始时装了一幅图片(用的fillrect),
Form1.Repaint;
pic1:=Rect(0,0,image1.width,image1.height);
image1.Canvas.FillRect(pic1);
image1.Transparent := True; //
image1.Canvas.Pen.Color:=clRed; //
image1.Canvas.Pen.Style:=psSolid; //
image1.Canvas.Brush.Color:=clBtnFace; //
image1.Canvas.Brush.Style:=bsSolid;//设置属性;
BitMap1:=TBitMap.Create;
BitMap1.LoadFromFile('C:/WINNT/Web/Wallpaper/4.bmp');
Form1.image1.Canvas.stretchDraw(pic1,BitMap1);
现在要根据图片大小重装图片,所以用了一下语句:
Image1.Canvas.FillRect(Image1.Canvas.ClipRect);刷新
if (Bitmap1.Height>Image1.Height) and (bitmap1.Width<Image1.Width) then
begin
kx:=Bitmap1.Height div Image1.Height;
Dek:=Bitmap1.Width div kx;
left:=((Image1.Width-Dek) div 2);
top:=0;
right:=((Image1.Width+Dek) div 2);
bottom:=Image1.Height;
pic1:=Rect(left,top,right,bottom);
image1.Canvas.FillRect(pic1);运行这里就出错。
Image1.picture.BitMap.Assign(bitmap1);
end
else if (Bitmap1.Height<Image1.Height) and (bitmap1.Width>Image1.Width) then
begin
kx:=Bitmap1.Width div Image1.Width;
Dek:=Bitmap1.height div kx;
left:=0;
top:=((Image1.Height-Dek) div 2);;
right:=Image1.width;
bottom:=((Image1.height+Dek) div 2);
pic1:=Rect(left,top,right,bottom);
image1.Canvas.FillRect(pic1);
Image1.picture.BitMap.Assign(bitmap1);
end
else if (Bitmap1.Height>Image1.Height) and (bitmap1.Width>Image1.Width) then
begin
if (Bitmap1.Height div Image1.height)<(Bitmap1.Width div Image1.Width) then
begin
kx:=Bitmap1.Width div Image1.Width;
Dek:=Bitmap1.height div kx;
left:=0;
top:=((Image1.Height-Dek) div 2);;
right:=Image1.width;
bottom:=((Image1.height+Dek) div 2);
pic1:=Rect(left,top,right,bottom);
image1.Canvas.FillRect(pic1);
Image1.picture.BitMap.Assign(bitmap1);
end
else begin
kx:=Bitmap1.Height div Image1.Height;
Dek:=Bitmap1.Width div kx;
left:=((Image1.Width-Dek) div 2);
top:=0;
right:=((Image1.Width+Dek) div 2);
bottom:=Image1.Height;
pic1:=Rect(left,top,right,bottom);
image1.Canvas.FillRect(pic1);
Image1.picture.BitMap.Assign(bitmap1);
end;
end
else begin
left:=((Image1.width-bitmap1.width) div 2);
top:=((Image1.height-bitmap1.height) div 2);
right:=((Image1.width+bitmap1.width) div 2);
bottom:=((Image1.height+bitmap1.height) div 2);
Image1.Canvas.FillRect(pic1);
Image1.picture.Bitmap.Assign(bitmap1);
end;
不知道什么原因阿!!!