{"id":135,"date":"2007-05-12T14:59:10","date_gmt":"2007-05-12T12:59:10","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/print-timage\/"},"modified":"2007-05-12T14:59:12","modified_gmt":"2007-05-12T12:59:12","slug":"print-timage","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/print-timage\/","title":{"rendered":"Print TImage"},"content":{"rendered":"<p>[code lang=&#8221;delphi&#8221;]procedure TForm1.PrintBitmap(TheImage : TImage);<br \/>\nvar<br \/>\n  SourceRect, PrintRect: TRect;<br \/>\n  Info: PBitmapInfo;<br \/>\n  InfoSize: Integer;<br \/>\n  Image: Pointer;<br \/>\n  ImageSize: LongInt;<br \/>\n  Bits: HBitmap;<br \/>\n  DIBWidth, DIBHeight: LongInt;<br \/>\n  PrintWidth, PrintHeight: LongInt;<br \/>\n  PrintBitmap: TBitmap;<br \/>\nbegin<br \/>\n  Printer.BeginDoc;<br \/>\n  PrintBitmap := TBitmap.Create;<br \/>\n  SourceRect.Left := TheImage.Left;<br \/>\n  SourceRect.Top := TheImage.Top;<br \/>\n  SourceRect.Right := TheImage.Left + Image1.Width;<br \/>\n  SourceRect.Bottom := TheImage.Top + Image1.Height;<\/p>\n<p>  {  Set up the height and width of the destination bitmap }<br \/>\n  PrintBitmap.Height := SourceRect.Bottom &#8211; SourceRect.Top + 1;<br \/>\n  PrintBitmap.Width := SourceRect.Right &#8211; SourceRect.Left + 1;<\/p>\n<p>  {  Set the destination coordinates }<br \/>\n  PrintRect.Top := 0;<br \/>\n  PrintRect.Left := 0;<br \/>\n  PrintRect.Right := PrintBitmap.Width;<br \/>\n  PrintRect.Bottom := PrintBitmap.Height;<\/p>\n<p>  {  Copy from the screen to the printer }<br \/>\n  PrintBitmap.Canvas.CopyRect(PrintRect, self.Canvas, SourceRect);<\/p>\n<p>{  Here we will stretch the bitmap, and do the printing }<br \/>\n  With Printer, Canvas Do<br \/>\n  Begin<br \/>\n    { Get the handle to the Print bitmap }<br \/>\n    Bits := PrintBitmap.Handle;<\/p>\n<p>    {  Get the information from the bitmap }<br \/>\n    GetDIBSizes(Bits, InfoSize, ImageSize);<\/p>\n<p>    { Allocate the required memory for the operation }<br \/>\n    GetMem(Info,  InfoSize);<br \/>\n    Try<br \/>\n    GetMem(Image, ImageSize);<br \/>\n      Try<br \/>\n        GetDIB(Bits, 0, Info^, Image^);<br \/>\n        With Info^.bmiHeader Do<br \/>\n        Begin<br \/>\n          DIBWidth := biWidth;<br \/>\n          DIBHeight := biHeight;<br \/>\n        End;<br \/>\n{  Adjust the print sizes (expand or contract) }<br \/>\n        PrintWidth := MulDiv(DIBWidth, GetDeviceCaps(Handle,<br \/>\n                               LOGPIXELSX), PixelsPerInch);<br \/>\n       PrintHeight := MulDiv(DIBHeight, GetDeviceCaps(Handle,<br \/>\n                               LOGPIXELSY), PixelsPerInch);<br \/>\n{  Move from one canvas to the other while stretching or compressing<br \/>\nthe image }<br \/>\n       StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0,<br \/>\n                             0,DIBWidth, DIBHeight, Image, Info^,<br \/>\n                             DIB_RGB_COLORS, SRCCOPY);<br \/>\n        Finally<\/p>\n<p>          FreeMem(Image, ImageSize);<br \/>\n        End;<br \/>\n      Finally<br \/>\n        FreeMem(Info, InfoSize);<br \/>\n      End;<br \/>\n    End;<br \/>\n    Printer.EndDoc;<br \/>\nend;<br \/>\n[\/code]<\/p>\n<p>[tags]Delphi, Graphic[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[code lang=&#8221;delphi&#8221;]procedure TForm1.PrintBitmap(TheImage : TImage); var SourceRect, PrintRect: TRect; Info: PBitmapInfo; InfoSize: Integer; Image: Pointer; ImageSize: LongInt; Bits: HBitmap; DIBWidth, DIBHeight: LongInt; PrintWidth,&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[75,101],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-2b","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/135"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}