Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 31.01.2007, 18:10   #1
1123
Новичок
Джуниор
 
Регистрация: 31.01.2007
Сообщений: 1
По умолчанию Печать изображения

Доброго времени суток всем!!! У меня проблема - не могу распечатать изображение из компонента TImage так, чтобы оно печаталось на весь лист А4. Кто-нибудь помогите с этим вопросом, пожалуйста. (Разрешение рисунка и, соответственно TImage, - 880x1244).
Код, используемый мной:

Код:
procedure TForm1.Button3Click(Sender: TObject);
begin
  with Printer do
    begin
      BeginDoc;
      Canvas.Draw(0, 0, Image1.Picture.Graphic);
      EndDoc ;
    end;
end;
1123 вне форума Ответить с цитированием
Старый 31.01.2007, 19:29   #2
zetrix
Delphi/C++/C#
Участник клуба
 
Аватар для zetrix
 
Регистрация: 29.10.2006
Сообщений: 1,972
По умолчанию

Картинка должна быть в Image1.

Код:
procedure TForm1.Button1Click(Sender: TObject);
var
 X1,X2,Y1,Y2:Integer;
 PointsX,PointsY:double;
 PrintDlg:TPrintDialog;
begin
 PrintDlg:=TPrintDialog.Create(Owner);
 if PrintDlg.Execute then
  begin
   Printer.BeginDoc;
   Printer.Canvas.Refresh;
   PointsX:=GetDeviceCaps(Printer.Canvas.Handle,LOGPIXELSX)/70;
   PointsY:=GetDeviceCaps(Printer.Canvas.Handle,LOGPIXELSY)/70;

   X1:=round((Printer.PageWidth - Image1.Picture.Bitmap.Width*PointsX)/2);
   Y1:=round((Printer.PageHeight - Image1.Picture.Bitmap.Height*PointsY)/2);
   X2:=round(X1+Image1.Picture.Bitmap.Width*PointsX);
   Y2:=round(Y1+Image1.Picture.Bitmap.Height*PointsY);
   Printer.Canvas.CopyRect(Rect(X1,Y1,X2,Y2),Image1.Picture.Bitmap.Canvas,
             Rect(0,0,Image1.Picture.Bitmap.Width,Image1.Picture.Bitmap.Height));

   Printer.EndDoc;
  end;
 PrintDlg.Free;
end;
zetrix вне форума Ответить с цитированием
Старый 31.01.2007, 20:45   #3
Umen
Форумчанин
 
Аватар для Umen
 
Регистрация: 10.11.2006
Сообщений: 189
По умолчанию

Вот ешё варианты:

Код:
uses  
  Printers;  
procedure TForm1.Button1Click(Sender: TObject);  
var  
  ScaleX, ScaleY: Integer;  
  RR: TRect;  
begin  
  with Printer do  
  begin  
    BeginDoc;  
    // The StartDoc function starts a print job.  
    try  
      ScaleX := GetDeviceCaps(Handle, logPixelsX) div PixelsPerInch;  
      ScaleY := GetDeviceCaps(Handle, logPixelsY) div PixelsPerInch;  
      // 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);  
      // Stretch to fit  
    finally  
      EndDoc;    
    end;  
  end;  
end;
Код:
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};
Код:
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;
Umen вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Изображения в WebBrowser. Teen4jump Работа с сетью в Delphi 3 15.08.2008 12:13
Чтение изображения из базы данных, Вместо изображения - "System.Byte[]" ruelCrow Общие вопросы .NET 3 10.07.2008 23:29
Вращение изображения beginner JavaScript, Ajax 5 07.07.2008 23:44
image. печать большого изображения на нескольких листах OLEG'arh Общие вопросы Delphi 1 20.06.2008 13:06
Изображения в БД alikon1 БД в Delphi 3 08.10.2007 13:13