방안 #1
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;
방안 #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};
방안 #3
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;관련링크 : http://mc-computing.com/languages/Delphi/Printing.html
'프로그래밍 > Delphi' 카테고리의 다른 글
이미지 파일명을 가지고 이미지 사이즈(폭/높이) 알아내기 (0) | 2011.07.19 |
---|---|
Twitter for Delphi(델파이를 이용한 트위터 클라이언트 제작) (3) | 2011.07.13 |
파일사이즈 알아내기 - in Delphi (0) | 2011.03.02 |
SMTP를 이용하여 메일 발송시 아이폰에서 한글 깨지는 문제 처리 (0) | 2011.02.10 |
설정된 프린터 용지 얻기 및 설정하기 (1) | 2011.01.30 |