那
那年黄梅花开
Unregistered / Unconfirmed
GUEST, unregistred user!
我想把dbgrid保存为jpeg图片
有两个问题
1 加上button1.visible时保存的图片为空白图片
2 加上setControlVisible(false)时程序最后会报错:abstract error等等
procedure TForm1.Button1Click(Sender: TObject);
var
BMP: TBitMap;
tpJpg:TJpegImage;
Rect,SRect:TRect;
ileft,itop,iwidth,iheight: integer;//记录以前的一些变量
begin
ileft:= dbgrid1.left;
itop:= dbgrid1.top;
iwidth:= dbgrid1.width;
iheight:= dbgrid1.height;
DBGrid1.SetBounds(0,0,ClientWidth,ClientHeight);//max
//setControlVisible(false);
//Button1.visible:= false;
BMP := TBitMap.Create;
tpJpg:=TJpegImage.create;
try
BMP.Width := self.ClientWidth ;
BMP.Height := self.ClientHeight;
SRect.Left := 0;
SRect.Top := 0;
SRect.Right := Bmp.Width;
SRect.Bottom:= Bmp.Height;
Rect := SRect;
Rect.Left := Rect.Left;
Rect.Top := Rect.Top;
bmp.PixelFormat := pf24bit;
BMP.Canvas.CopyRect(Rect, self.Canvas, SRect);
tpJpg.Assign(BMP);
tpJpg.SaveToFile('gg.jpg');
Finally
Bmp.Free;
tpJpg.Free;
with DBGrid1 do
SetBounds(ileft,itop,iWidth,iHeight); //restore
//setControlVisible(true);
end;
end;
procedure TForm1.setControlVisible(bVisible: boolean);
var
i: integer;
begin
for i:= 0 to self.ComponentCount-1 do
if TWinControl(Components).Name<> DBGrid1.Name then
TWinControl(self.Components).Visible:= bVisible;
end;
有两个问题
1 加上button1.visible时保存的图片为空白图片
2 加上setControlVisible(false)时程序最后会报错:abstract error等等
procedure TForm1.Button1Click(Sender: TObject);
var
BMP: TBitMap;
tpJpg:TJpegImage;
Rect,SRect:TRect;
ileft,itop,iwidth,iheight: integer;//记录以前的一些变量
begin
ileft:= dbgrid1.left;
itop:= dbgrid1.top;
iwidth:= dbgrid1.width;
iheight:= dbgrid1.height;
DBGrid1.SetBounds(0,0,ClientWidth,ClientHeight);//max
//setControlVisible(false);
//Button1.visible:= false;
BMP := TBitMap.Create;
tpJpg:=TJpegImage.create;
try
BMP.Width := self.ClientWidth ;
BMP.Height := self.ClientHeight;
SRect.Left := 0;
SRect.Top := 0;
SRect.Right := Bmp.Width;
SRect.Bottom:= Bmp.Height;
Rect := SRect;
Rect.Left := Rect.Left;
Rect.Top := Rect.Top;
bmp.PixelFormat := pf24bit;
BMP.Canvas.CopyRect(Rect, self.Canvas, SRect);
tpJpg.Assign(BMP);
tpJpg.SaveToFile('gg.jpg');
Finally
Bmp.Free;
tpJpg.Free;
with DBGrid1 do
SetBounds(ileft,itop,iWidth,iHeight); //restore
//setControlVisible(true);
end;
end;
procedure TForm1.setControlVisible(bVisible: boolean);
var
i: integer;
begin
for i:= 0 to self.ComponentCount-1 do
if TWinControl(Components).Name<> DBGrid1.Name then
TWinControl(self.Components).Visible:= bVisible;
end;