Недавно добавленные исходники

•  Animation Loaders  799

•  DeLiKaTeS Tetris (Тетрис)  5 769

•  TDictionary Custom Sort  7 724

•  Fast Watermark Sources  7 402

•  3D Designer  10 623

•  Sik Screen Capture  7 937

•  Patch Maker  8 159

•  Айболит (remote control)  8 207

•  ListBox Drag & Drop  7 012

•  Доска для игры Реверси  100 369

•  Графические эффекты  8 282

•  Рисование по маске  7 658

•  Перетаскивание изображений  6 262

•  Canvas Drawing  6 637

•  Рисование Луны  6 560

•  Поворот изображения  5 719

•  Рисование стержней  4 656

•  Paint on Shape  3 355

•  Генератор кроссвордов  4 327

•  Головоломка Paletto  3 485

•  Теорема Монжа об окружностях  4 301

•  Пазл Numbrix  2 781

•  Заборы и коммивояжеры  3 707

•  Игра HIP  2 503

•  Игра Go (Го)  2 495

•  Симулятор лифта  2 889

•  Программа укладки плитки  2 321

•  Генератор лабиринта  3 049

•  Проверка числового ввода  2 552

•  HEX View  2 956

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

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



Автор: http://www.experts-exchange.com

uses
  printers;

procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);
var
  Header, Bits: Pointer;
  HeaderSize: DWORD;
  BitsSize: DWORD;
begin
  GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);
  Header := AllocMem(HeaderSize);
  Bits := AllocMem(BitsSize);
  try
    GetDIB(ABitmap.Handle, ABitmap.Palette, Header^, Bits^);
    StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,
      DestRect.Right, DestRect.Bottom,
      0, 0, ABitmap.Width, ABitmap.Height, Bits, TBitmapInfo(Header^),
      DIB_RGB_COLORS, SRCCOPY);
  finally
    FreeMem(Header, HeaderSize);
    FreeMem(Bits, BitsSize);
  end;
end;

procedure PrintImage(Image: TImage; ZoomPercent: Integer);
// if ZoomPercent=100, Image will be printed across the whole page
var
  relHeight, relWidth: integer;
begin
  Screen.Cursor := crHourglass;
  Printer.BeginDoc;
  with Image.Picture.Bitmap do
  begin
    if ((Width / Height) > (Printer.PageWidth / Printer.PageHeight)) then
    begin
      // Stretch Bitmap to width of PrinterPage
      relWidth := Printer.PageWidth;
      relHeight := MulDiv(Height, Printer.PageWidth, Width);
    end
    else
    begin
      // Stretch Bitmap to height of PrinterPage
      relWidth := MulDiv(Width, Printer.PageHeight, Height);
      relHeight := Printer.PageHeight;
    end;
    relWidth := Round(relWidth * ZoomPercent / 100);
    relHeight := Round(relHeight * ZoomPercent / 100);
    DrawImage(Printer.Canvas, Rect(0, 0, relWidth, relHeight),
      Image.Picture.Bitmap);
  end;
  Printer.EndDoc;
  Screen.cursor := crDefault;
end;

// Example Call:

procedure TForm1.Button1Click(Sender: TObject);
begin
  // Print image at 40% zoom:
  PrintImage(Image1, 40);
end;







Copyright © 2004-2026 "Delphi Sources" by «SiteAnalyzer». Delphi World FAQ

Группа ВКонтакте