I have had problems trying to print TImage.Canvas using Delphi 6. The way I have got round this is by transferring eachg pixel one at a time to TPrinter.Canvas (as below). This does not seem very elegant. Is there a better way?
{This assumes that the image, when printed, is smaller than the page}
procedure TForm1.PrintImageClick(Sender: TObject);
var
x,y,Counter,ScaleFactorInxDirection,ScaleFactorInyDirection,ScaleFactor: integer;
begin
If (Printer.PageWidth Div Image1.Width) = (Printer.PageWidth / Image1.Width)
Then ScaleFactorInxDirection := Printer.PageWidth Div Image1.Width - 1
Else ScaleFactorInxDirection := Printer.PageWidth Div Image1.Width;
If (Printer.PageHeight Div Image1.Height) = (Printer.PageHeight / Image1.Height)
Then ScaleFactorInxDirection := Printer.PageHeight Div Image1.Height - 1
Else ScaleFactorInxDirection := Printer.PageHeight Div Image1.Height;
If ScaleFactorInxDirection < ScaleFactorInyDirection
Then ScaleFactor := ScaleFactorInxDirection
Else ScaleFactor := ScaleFactorInyDirection;
Printer.BeginDoc;
For x := 1 To Image1.Width
Do
For y := 1 To Image1.Height
Do
For Counter := Printer.PageWidth - Image1.Width To Printer.PageWidth - Image1.Width + m
Do Printer.Canvas.Pixels[Counter + ScaleFactor * x,Counter + ScaleFactor * y] := Graph1.Canvas.Pixels[x,y];
Printer.EndDoc;
end;
{This assumes that the image, when printed, is smaller than the page}
procedure TForm1.PrintImageClick(Sender: TObject);
var
x,y,Counter,ScaleFactorInxDirection,ScaleFactorInyDirection,ScaleFactor: integer;
begin
If (Printer.PageWidth Div Image1.Width) = (Printer.PageWidth / Image1.Width)
Then ScaleFactorInxDirection := Printer.PageWidth Div Image1.Width - 1
Else ScaleFactorInxDirection := Printer.PageWidth Div Image1.Width;
If (Printer.PageHeight Div Image1.Height) = (Printer.PageHeight / Image1.Height)
Then ScaleFactorInxDirection := Printer.PageHeight Div Image1.Height - 1
Else ScaleFactorInxDirection := Printer.PageHeight Div Image1.Height;
If ScaleFactorInxDirection < ScaleFactorInyDirection
Then ScaleFactor := ScaleFactorInxDirection
Else ScaleFactor := ScaleFactorInyDirection;
Printer.BeginDoc;
For x := 1 To Image1.Width
Do
For y := 1 To Image1.Height
Do
For Counter := Printer.PageWidth - Image1.Width To Printer.PageWidth - Image1.Width + m
Do Printer.Canvas.Pixels[Counter + ScaleFactor * x,Counter + ScaleFactor * y] := Graph1.Canvas.Pixels[x,y];
Printer.EndDoc;
end;