How to Copy a Canvas to another Canvas lazarus / 13-General ---------------------------------------------------------------------- matutetandil · 2008-06-13 15:24 Hi, I trying to print some draws that i have in the canvas of a DrawGrid. I made a procedure to copy all the information of the DrawGrid's canvas to the Printer's Canvas, but it don't work... someone have any ideas... This is the procedure: Code: [Select]procedure CopyCanvas(var p : TPrinter); var i,j : Integer; begin     for i:=0 to DrawGrid1.Canvas.Width do         for j:=0 to DrawGrid1.Canvas.Height do begin             p.Canvas.Pen.Color:= DrawGrid1.Canvas.Pixels[i,j];             p.Canvas.Line(i,j,i,j);         end; end; basically what I need is a procedure to clone a canvas to another canvas P.S.: sorry for my english... ---------------------------------------------------------------------- Phil · 2008-06-13 17:22 Quote from: "matutetandil" basically what I need is a procedure to clone a canvas to another canvas With Delphi, TCanvas has a BrushCopy method that might be what you need, but BrushCopy is not implemented in the LCL's TCanvas. You might be able to simulate it like this as a standalone procedure: procedure BrushCopy(DestCanvas: TCanvas; const Dest: TRect; Bitmap: TBitmap;                     const Source: TRect; Color: TColor); begin   StretchBlt(DestCanvas.Handle, Dest.Left, Dest.Top,              Dest.Right - Dest.Left, Dest.Bottom - Dest.Top,              Bitmap.Canvas.Handle, Source.Left, Source.Top,              Source.Right - Source.Left, Source.Bottom - Source.Top, SrcCopy); end; StretchBlt is a Win API function that's also in LclIntf and should be implemented on most widgetsets. Thanks. -Phil ---------------------------------------------------------------------- Zaher · 2008-06-13 22:22 using Canvas.Pixels[i,j] is very slow Did you try Canvas.CopyRect(... ---------------------------------------------------------------------- Phil · 2008-06-14 01:12 Quote from: "zaher"using Canvas.Pixels[i,j] is very slow Did you try Canvas.CopyRect(... Probably a better idea. CopyRect has just about the same code, but with some error checking. Maybe CopyRect is relatively new? I don't think it was there when I came up with the BrushCopy workaround. Keeping up with the LCL is almost a full-time job... Thanks. -Phil ---------------------------------------------------------------------- theo · 2008-06-14 09:29 CopyRect is nothing new. There's also in TWinControl:     procedure PaintTo(DC: HDC; X, Y: Integer); virtual; overload;     procedure PaintTo(ACanvas: TCanvas; X, Y: Integer); overload; I don't know if this works for all widget sets. ---------------------------------------------------------------------- matutetandil · 2008-06-14 23:54 ok... i'll try it...    if I'm lucky i'll post the winner procedure... see u soon...