Printing Delphi

procedure TForm1.PrintBitmap(TheImage : TImage);
var
SourceRect, PrintRect: TRect;
Info: PBitmapInfo;
InfoSize: Integer;
Image: Pointer;
ImageSize: LongInt;
Bits: HBitmap;
DIBWidth, DIBHeight: LongInt;
PrintWidth, PrintHeight: LongInt;
PrintBitmap: TBitmap;
begin
Printer.BeginDoc;
PrintBitmap := TBitmap.Create;
SourceRect.Left := TheImage.Left;
SourceRect.Top := TheImage.Top;
SourceRect.Right := TheImage.Left + Image1.Width;
SourceRect.Bottom := TheImage.Top + Image1.Height;
{ Set up the height and width of the destination bitmap }
PrintBitmap.Height := SourceRect.Bottom - SourceRect.Top + 1;
PrintBitmap.Width := SourceRect.Right - SourceRect.Left + 1;
{ Set the destination coordinates }
PrintRect.Top := 0;
PrintRect.Left := 0;
PrintRect.Right := PrintBitmap.Width;
PrintRect.Bottom := PrintBitmap.Height;
{ Copy from the screen to the printer }
PrintBitmap.Canvas.CopyRect(PrintRect, self.Canvas, SourceRect);
{ Here we will stretch the bitmap, and do the printing }
With Printer, Canvas Do
Begin
{ Get the handle to the Print bitmap }
Bits := PrintBitmap.Handle;
{ Get the information from the bitmap }
GetDIBSizes(Bits, InfoSize, ImageSize);
{ Allocate the required memory for the operation }
GetMem(Info, InfoSize);
Try
GetMem(Image, ImageSize);
Try
GetDIB(Bits, 0, Info^, Image^);
With Info^.bmiHeader Do
Begin
DIBWidth := biWidth;
DIBHeight := biHeight;
End;
{ Adjust the print sizes (expand or contract) }
PrintWidth := MulDiv(DIBWidth, GetDeviceCaps(Handle,
LOGPIXELSX), PixelsPerInch);
PrintHeight := MulDiv(DIBHeight, GetDeviceCaps(Handle,
LOGPIXELSY), PixelsPerInch);
{ Move from one canvas to the other while stretching or compressing
the image }
StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0,
0,DIBWidth, DIBHeight, Image, Info^,
DIB_RGB_COLORS, SRCCOPY);
Finally
FreeMem(Image, ImageSize);
End;
Finally
FreeMem(Info, InfoSize);
End;
End;
Printer.EndDoc;
end;
//Kaan//