我在PAINTBOX控件上作图,该怎么保存?
我试着将PAINTBOX控件上的图拷贝到IMAGE上,可是只能保存当前可见的部分,滚动条以外的部分不能保存,清各位帮忙了,谢谢!急!

解决方案 »

  1.   

    是你保存方法不对吧,我以前也遇到过,后改成下面的形式。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        PaintBox: TPaintBox;
        Button1: TButton;
        Image: TImage;
        procedure Button1Click(Sender: TObject);
        procedure PaintBoxPaint(Sender: TObject);
      private
        { Private declarations }
        procedure DrawGrahpic(ACanvas:TCanvas);
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DrawGrahpic(ACanvas: TCanvas);
    begin
      with ACanvas do
      begin
        MoveTo(10,10);
        LineTo(10,100);
        LineTo(100,100);
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      bmp :TBitmap;
    begin
      bmp :=TBitmap.Create;
      bmp.PixelFormat:=pf4bit;
      bmp.Width :=PaintBox.Width;
      bmp.Height :=PaintBox.Height;  ///关键是下面这句,一定要和PaintBox的OnPaint上画图函数一样
      DrawGrahpic(bmp.Canvas);  Image.AutoSize:=True;
      Image.Stretch:=True;
      Image.Picture.Bitmap.Assign(bmp);
      bmp.Free;
      Image.Picture.SaveToFile('c:\a.bmp'); //保存
    end;procedure TForm1.PaintBoxPaint(Sender: TObject);
    begin
      DrawGrahpic(PaintBox.Canvas);
    end;end.