procedure TForm1.SavePicClick(Sender: TObject); var i:Integer; str:string; begin for i:=1 to 100 do begin if FileExists(str) then else begin str:='D:\Borland\Delphi7\Projects\mychart\pic'+inttostr(i)+'.bmp'; Image1.Picture.SaveToFile(str); str:='D:\Borland\Delphi7\Projects\mychart\pic'+inttostr(i+1)+'.bmp'; Image2.Picture.SaveToFile(str); exit; end; end;end;
提供一个这样的函数给你参考:procedure TFrmDesktop.FixSize(const vFileName: String); var vBitmap3: TBitmap; vImage: TImage; // DC2, vDC: HDC; begin try vImage := TImage.Create(self); vImage.Visible := False; vImage.AutoSize := true; vBitmap3 := TBitmap.Create; // vBitmap3.Width := 800; // vBitmap3.Height := 600; if CompareText(vExt, 'Bmp') = 0 then vImage.Picture.LoadFromFile(OpenDialog1.FileName); if CompareText(vExt, 'Jpg') = 0 then vImage.Picture.LoadFromFile(vFileName); if vImage.Picture.Bitmap.Height / vImage.Picture.Bitmap.Width > 0.75 then begin if vImage.Picture.Bitmap.Height >= ScreenY then begin vImage.Canvas.StretchDraw(Rect(0,0,round(vImage.Picture.Bitmap.Width * ScreenY/vImage.Picture.Bitmap.Height),ScreenY),vImage.Picture.Bitmap); vImage.Center := True; vBitmap3.Width := round(vImage.Picture.Bitmap.Width * ScreenY/vImage.Picture.Bitmap.Height); vBitmap3.Height := ScreenY; // StretchBlt(vDC, 0, 0, 800, 600, DC2, Image2.Left, Image2.Top, Image2.Width, Image2.Height, SRCCOPY); // vImage.Canvas.CopyRect(Rect(0,0, vImage.Width,vImage.Height), Image2.Canvas, Rect(0,0,Image2.Width,Image2.Height)); vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), vImage.Canvas, Rect(0,0,round(vImage.Picture.Bitmap.Width * ScreenY/vImage.Picture.Bitmap.Height),ScreenY)); // vImage.Picture.SaveToFile('E:\My Documents\My Pictures\Wally.bmp'); // vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), Image2.Canvas, Rect(0,0,Image2.Width,Image2.Height)); // if StretchBlt(vDC, 0, 0, 800, 600, DC2, Image2.Left, Image2.Top, Image2.Width, Image2.Height, SRCCOPY) then // BitBlt(vDC, 0, 0, 800, 600, DC2, Image2.Width, Image2.Height, SRCCOPY); // Image2.Picture.Graphic.SaveToFile('E:\My Documents\My Pictures\Wally.bmp'); vBitmap3.SaveToFile(vFileName); end else vImage.Picture.Bitmap.SaveToFile(vFileName); end else if vImage.Picture.Bitmap.Height / vImage.Picture.Bitmap.Width < 0.75 then begin if vImage.Picture.Bitmap.Width >= ScreenX then begin vImage.Canvas.StretchDraw(Rect(0,0,ScreenX,round(vImage.Picture.Bitmap.Height * ScreenX/vImage.Picture.Bitmap.Width)),vImage.Picture.Bitmap); vImage.Center := True; vBitmap3.Height := round(vImage.Picture.Bitmap.Height * ScreenX/vImage.Picture.Bitmap.Width); vBitmap3.Width := ScreenX; vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), vImage.Canvas, Rect(0, 0, ScreenX, round(vImage.Picture.Bitmap.Height * ScreenX/vImage.Picture.Bitmap.Width))); vBitmap3.SaveToFile(vFileName); end else vImage.Picture.Bitmap.SaveToFile(vFileName); end else begin if vImage.Picture.Bitmap.Height >= ScreenY then begin vImage.Canvas.StretchDraw(Rect(0,0,ScreenX,ScreenY),vImage.Picture.Bitmap); vImage.Center := True; vBitmap3.Width := ScreenX; vBitmap3.Height := ScreenY; vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), vImage.Canvas, Rect(0,0,ScreenX,ScreenY)); vBitmap3.SaveToFile(vFileName); end else vImage.Picture.Bitmap.SaveToFile(vFileName); end; finally vImage.free; end; end;
不过可以用Image控件的Canvas画图.
然后image1.Picture.SaveToFile试试看
var
i:Integer;
str:string;
begin
for i:=1 to 100 do
begin
if FileExists(str) then else
begin
str:='D:\Borland\Delphi7\Projects\mychart\pic'+inttostr(i)+'.bmp';
Image1.Picture.SaveToFile(str);
str:='D:\Borland\Delphi7\Projects\mychart\pic'+inttostr(i+1)+'.bmp';
Image2.Picture.SaveToFile(str);
exit;
end;
end;end;
var
vBitmap3: TBitmap;
vImage: TImage;
// DC2, vDC: HDC;
begin
try
vImage := TImage.Create(self);
vImage.Visible := False;
vImage.AutoSize := true;
vBitmap3 := TBitmap.Create;
// vBitmap3.Width := 800;
// vBitmap3.Height := 600;
if CompareText(vExt, 'Bmp') = 0 then vImage.Picture.LoadFromFile(OpenDialog1.FileName);
if CompareText(vExt, 'Jpg') = 0 then vImage.Picture.LoadFromFile(vFileName);
if vImage.Picture.Bitmap.Height / vImage.Picture.Bitmap.Width > 0.75 then
begin
if vImage.Picture.Bitmap.Height >= ScreenY then
begin
vImage.Canvas.StretchDraw(Rect(0,0,round(vImage.Picture.Bitmap.Width * ScreenY/vImage.Picture.Bitmap.Height),ScreenY),vImage.Picture.Bitmap);
vImage.Center := True;
vBitmap3.Width := round(vImage.Picture.Bitmap.Width * ScreenY/vImage.Picture.Bitmap.Height);
vBitmap3.Height := ScreenY;
// StretchBlt(vDC, 0, 0, 800, 600, DC2, Image2.Left, Image2.Top, Image2.Width, Image2.Height, SRCCOPY);
// vImage.Canvas.CopyRect(Rect(0,0, vImage.Width,vImage.Height), Image2.Canvas, Rect(0,0,Image2.Width,Image2.Height));
vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), vImage.Canvas, Rect(0,0,round(vImage.Picture.Bitmap.Width * ScreenY/vImage.Picture.Bitmap.Height),ScreenY));
// vImage.Picture.SaveToFile('E:\My Documents\My Pictures\Wally.bmp');
// vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), Image2.Canvas, Rect(0,0,Image2.Width,Image2.Height));
// if StretchBlt(vDC, 0, 0, 800, 600, DC2, Image2.Left, Image2.Top, Image2.Width, Image2.Height, SRCCOPY) then
// BitBlt(vDC, 0, 0, 800, 600, DC2, Image2.Width, Image2.Height, SRCCOPY);
// Image2.Picture.Graphic.SaveToFile('E:\My Documents\My Pictures\Wally.bmp');
vBitmap3.SaveToFile(vFileName);
end
else
vImage.Picture.Bitmap.SaveToFile(vFileName);
end
else if vImage.Picture.Bitmap.Height / vImage.Picture.Bitmap.Width < 0.75 then
begin
if vImage.Picture.Bitmap.Width >= ScreenX then
begin
vImage.Canvas.StretchDraw(Rect(0,0,ScreenX,round(vImage.Picture.Bitmap.Height * ScreenX/vImage.Picture.Bitmap.Width)),vImage.Picture.Bitmap);
vImage.Center := True;
vBitmap3.Height := round(vImage.Picture.Bitmap.Height * ScreenX/vImage.Picture.Bitmap.Width);
vBitmap3.Width := ScreenX;
vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), vImage.Canvas, Rect(0, 0, ScreenX, round(vImage.Picture.Bitmap.Height * ScreenX/vImage.Picture.Bitmap.Width)));
vBitmap3.SaveToFile(vFileName);
end
else
vImage.Picture.Bitmap.SaveToFile(vFileName);
end
else
begin
if vImage.Picture.Bitmap.Height >= ScreenY then
begin
vImage.Canvas.StretchDraw(Rect(0,0,ScreenX,ScreenY),vImage.Picture.Bitmap);
vImage.Center := True;
vBitmap3.Width := ScreenX;
vBitmap3.Height := ScreenY;
vBitmap3.Canvas.CopyRect(Rect(0,0,vBitmap3.Width,vBitmap3.Height), vImage.Canvas, Rect(0,0,ScreenX,ScreenY));
vBitmap3.SaveToFile(vFileName);
end
else
vImage.Picture.Bitmap.SaveToFile(vFileName);
end;
finally
vImage.free;
end;
end;