На главную
Подписка
Новости


Рейтинг@Mail.ru











Главная / DELPHI / Часто задаваемые вопросы и ответы на них / ОС и железо / Распечатать TImage Сделать домашней страницей Добавить в избранное Написать писмо

Распечатать TImage



{1.}
uses 
  printers; 

procedure TForm1.Button1Click(Sender: TObject); 
var  
  ScaleX, ScaleY: Integer; 
  RR: TRect; 
begin 
  with Printer do 
  begin 
    BeginDoc; 
    // Mit BeginDoc wird ein Druckauftrag initiiert. 
    // The StartDoc function starts a print job. 
    try 
      ScaleX := GetDeviceCaps(Handle, logPixelsX) div PixelsPerInch; 
      ScaleY := GetDeviceCaps(Handle, logPixelsY) div PixelsPerInch; 
      // Informationen uber die Auflosung 
      // Retrieves information about the Pixels per Inch of the Printer. 
      RR := Rect(0, 0, Image1.picture.Width * scaleX, Image1.Picture.Height * ScaleY); 
      Canvas.StretchDraw(RR, Image1.Picture.Graphic); 
      // An die Auflosung anpassen 
      // Stretch to fit 

    finally 
      EndDoc;   //Methode EndDoc beendet den aktuellen Druckauftrag und schlie?t die 
      // Textdatei-Variable. 
      // Steht in finally - um auch bei Abbruch des Druckauftrages Papierausgabe 
      // sicherzustellen 
    end; 
  end; 
end;


{2.} 

// Based on posting to borland.public.delphi.winapi by Rodney E Geraghty, 8/8/97. 


procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap); 
var 
  BitmapHeader: pBitmapInfo; 
  BitmapImage: Pointer; 
  HeaderSize: DWORD; 
  ImageSize: DWORD; 
begin 
  GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize); 
  GetMem(BitmapHeader, HeaderSize); 
  GetMem(BitmapImage, ImageSize); 
  try 
    GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^); 
    StretchDIBits(Canvas.Handle, 
      DestRect.Left, DestRect.Top,    // Destination Origin 
      DestRect.Right - DestRect.Left, // Destination Width 
      DestRect.Bottom - DestRect.Top, // Destination Height 
      0, 0,                           // Source Origin 
      Bitmap.Width, Bitmap.Height,    // Source Width & Height 
      BitmapImage, 
      TBitmapInfo(BitmapHeader^), 
      DIB_RGB_COLORS, 
      SRCCOPY) 
  finally 
    FreeMem(BitmapHeader); 
    FreeMem(BitmapImage) 
  end 
end {PrintBitmap};


Copyright ©   "DELPHI WORLD"   E-mail:   delphiworld@mail.ru  http://www.delphiworld.narod.ru
Источник получения информации: http://www.delphiworld.narod.ru
Hosted by uCoz