我已经成功地在Form上做了些图,请问怎么把它保存为一个图形文件??

解决方案 »

  1.   

    var
      Bitmap : TBitMap;
    begin
      Bitmap := TBitmap.Create;          BitMap.canvas.CopyRectBitMap.Canvas.ClipRect,Form1.Canvas,Form1.BoundsRect);
          BitMap.SaveToFile('E:\aa.bmp');
    end;
      

  2.   

    Form1.PaintTo(Canvas.Handle,0,0);************************************************************Draws the windowed control to a device context.procedure PaintTo(DC: HDC; X, Y: Integer);DescriptionCall PaintTo to draw the control on a device context. Specify the device context as the value of the DC parameter and specify the X and Y coordinates on the device context where the top-left corner of the windowed control is to be drawn. PaintTo first erases the background of the device context and then paints the control.PaintTo is useful for drawing an image of the control into a bitmap DC.Warning: When using PaintTo to draw on a canvas, you must lock the canvas first (and unlock it after the call to PaintTo. If you do not lock the canvas, Windows calls that occur while the control is painting can cause the canvas to lose its handle.
      

  3.   

    奇怪,用了ljmanage的方法保存的图是张白图,没有我画的东西。
    ?????
      

  4.   

    因为Form.Canvas并不永久保存Form上的图,Form一刷新,图就丢失了
      

  5.   

    procedure TForm1.FormPaint(Sender: TObject);
    begin
      canvas.Rectangle(0, 2, 100, 100);
     // bitblt(bmp.Handle, 0, 0, bmp.Width, bmp.Height, canvas.Handle, 0, 0, SRCCOPY);
    end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      //canvas.CopyRect(rect(0, 0, bmp.Width, bmp.Height), bmp.Canvas, rect(0, 0, width, height));
      bmp.Canvas.CopyRect(canvas.ClipRect, canvas, rect(0, 0, width, height));
      bmp.SaveToFile('d:\test.bmp');
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      bmp := TBitmap.Create;
      bmp.Width := form1.ClientWidth-2;
      bmp.Height := form1.ClientHeight-20;
    end;
      

  6.   

    我觉得还是在Form上加一个Picture吧,这样在Picture的Canvas上画的图不会消失
      

  7.   

    给你一个小程序, 希望对你有帮助.unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;type
      TForm1 = class(TForm)
        Bevel1: TBevel;
        procedure FormCreate(Sender: TObject);
        procedure FormPaint(Sender: TObject);
        procedure FormDblClick(Sender: TObject);
      private
        { Private declarations }
        Rect: Array[0..10] of TPoint;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    {$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
      i : Integer;
    begin
      Self.Canvas.Pen.Color := clBlue;
      for i := 0 to 10 do
      begin
          Self.Rect[i].X := Random(Self.Width);
          Self.Rect[i].Y := Random(Self.Height);
      end;
      Self.Bevel1.Align := alClient;
      Self.Bevel1.Visible := False;
    end;procedure TForm1.FormPaint(Sender: TObject);
    var
      i: Integer;
    begin
      Self.Canvas.MoveTo(Self.Rect[0].X, Self.Rect[0].Y);
      for i := 1 to 10 do
      begin
        Self.Canvas.LineTo(Self.Rect[i].X, Self.Rect[i].Y);
      end;
    end;procedure TForm1.FormDblClick(Sender: TObject);
    var
      Bit: TBitMap;
    begin
      Bit := TBitMap.Create;
      Bit.Width := Self.Bevel1.Width;
      Bit.Height := Self.Bevel1.Height;
      BitBlt(Bit.Canvas.Handle, 0, 0, Self.Bevel1.Width,
             Self.Bevel1.Height, Self.Canvas.Handle, 0, 0, SRCCOPY);
      Bit.SaveToFile('d:\aa.bmp');
      Bit.Free;
    end;end.