5,391
社区成员
发帖
与我相关
我的任务
分享
procedure TFrmSaveBmp.SaveButtonClick(Sender: TObject);
var
can: TCanvas;
bmp: TBitmap;
begin
//////////////////////////////////////////////////////////////////////////////
if SaveDialog.Execute then
begin
if FileExists(SaveDialog.FileName) then
if Application.MessageBox(PChar(Format(sOverWrite, [SaveDialog.FileName])),'提示',MB_YESNOCANCEL+MB_ICONINFORMATION)<>idyes then Exit;
can := TCanvas.Create;
bmp := TBitmap.Create;
try
bmp.Width := Editor.Width;
bmp.Height := Editor.Height;
bmp.PixelFormat:=pfDevice;
bmp.PixelFormat:=pf8bit;
can.Handle := GetDC(Editor.Handle);
bmp.Canvas.CopyRect(Rect(0,0,Editor.Width,Editor.Height),can,Editor.ClientRect);
bmp.SaveToFile(SaveDialog.FileName);
finally
bmp.Free;
can.Free;
end;
SetFileName(SaveDialog.FileName);
Editor.Modified := False;
SetModified(False);
end;
end;
var
//can: TCanvas;
bmp: TBitmap;
begin
//////////////////////////////////////////////////////////////////////////////
if SaveDialog.Execute then
begin
if FileExists(SaveDialog.FileName) then
if Application.MessageBox(PChar(Format(sOverWrite, [SaveDialog.FileName])),'提示',MB_YESNOCANCEL+MB_ICONINFORMATION)<>idyes then Exit;
//can := TCanvas.Create;
bmp := TBitmap.Create;
try
//can.Handle := GetDC(Editor.Handle);
bmp.Width := Editor.Width;
bmp.Height := Editor.Height;
bmp.PixelFormat:=pfDevice;
bmp.PixelFormat:=pf8bit;
BitBlt(bmp.Canvas.Handle,0,0,bmp.Width,bmp.Height,GetDC(Editor.Handle),0,0,SRCCOPY);
//bmp.Canvas.CopyRect(Rect(0,0,Editor.Width,Editor.Height),can,Editor.ClientRect);
bmp.SaveToFile(SaveDialog.FileName);
finally
bmp.Free;
//can.Free;
end;
Editor.Modified := False;
end;