{"id":208,"date":"2007-05-12T17:03:26","date_gmt":"2007-05-12T15:03:26","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/print-bitmap-as-dib\/"},"modified":"2007-05-12T17:03:27","modified_gmt":"2007-05-12T15:03:27","slug":"print-bitmap-as-dib","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/print-bitmap-as-dib\/","title":{"rendered":"Print Bitmap as DIB"},"content":{"rendered":"<p>Print Bitmap as DIB<br \/>\nby Boris Nienke<br \/>\n(you need a Form with a TImage and a TButton)<\/p>\n<p>&#8211; just for 24bit bitmaps. If bitmaps has less bits, then there may be a blank page on some HP printers! You can change color-depth with: &#8220;MyBitmap.PixelFormat := pf24bit&#8221;.<br \/>\n&#8211; or you need to fill the palette-entries (look at &#8220;A Better Way to Print a Form&#8221; (Borland Technical Info TI1412D.txt)<br \/>\n<!--more--><\/p>\n<p>[code lang=&#8221;delphi&#8221;]procedure MemFree(Ptr: Pointer; Size: Longint);<br \/>\nbegin<br \/>\n  if Size < 65535 then\n    FreeMem(Ptr, Size)\n  else\n    GlobalFreePtr(Ptr);\nend;\n\n  {Prints BitMap }\nprocedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);\nvar\n  Header, Bits: Pointer;\n  HeaderSize: Integer;\n  {$IfDef Win32}                   {Checks if using Delphi 2.0}\n  BitsSize : Integer;\n  {$Else}\n  BitsSize : LongInt;\n  {$EndIf}\nbegin\n  GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);\n  Header := AllocMem(HeaderSize);\n  Bits := AllocMem(BitsSize);\n  try\n    GetDIB(ABitmap.Handle, ABitmap.Palette, Header^, Bits^);\n    StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,\n        DestRect.Right - DestRect.Left, DestRect.Bottom - DestRect.Top,\n        0, 0, ABitmap.Width, ABitmap.Height, Bits, TBitmapInfo(Header^),\n        DIB_RGB_COLORS, SRCCOPY);\n  finally\n    MemFree(Header, HeaderSize);\n    MemFree(Bits, BitsSize);\n  end;\nend;\n\nprocedure TForm1.Button1Click(Sender: TObject);\nbegin\n  Printer.BeginDoc;\n\n  DrawImage(Printer.Canvas,\n            Rect(20, 30, 20+(image1.picture.bitmap.width * 7), 30+(image1.picture.bitmap.height * 7)),\n            image1.picture.bitmap);\n\n  Printer.EndDoc;\nend;\n[\/code]\n\n[tags]Delphi, Printing, Graphic[\/tags]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Print Bitmap as DIB by Boris Nienke (you need a Form with a TImage and a TButton) &#8211; just for 24bit bitmaps. If&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,119],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-3m","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/208"}],"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=208"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/208\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}