>>
APLDN Home

>>
Events

>>
Trainings

>>
APL Books

>>
APLDN Links

>>
Discussion Groups

>>
Downloads

>>
Articles

>>
Library

>>
Learning Tools

>>
APLDN User IO

>>
APL2000.com




General

Author Thread: Problem printing bmp file
JCarter
Problem printing bmp file
Posted: Wednesday, December 27, 2006 1:35 PM (EST)

I would like to include a bitmap file when printing. Paint indicates that the size is 7.5" x 10", but it prints out about 1" x 2". If I change my printer resolution from 1200 dpi. Here is the sample code:

 

'Prt' Œwi 'Create' 'Printer' ('caption' 'Print Bitmap')
'Prt' Œwi 'printername' 'Adobe PDF'
'Prt' Œwi 'orientation' 'landscape'
'Prt' Œwi 'Draw' ('Scale' 3) ('Bitmap' 'C:\Test.bmp' 0 0 720 960)
'Prt' Œwi 'Delete'


 


Comments:

Author Thread:
Mark.Osborne
Problem printing bmp file
Posted: Wednesday, December 27, 2006 2:23 PM (EST)

Jeff,

 

Here is how I do it (but I am printing just the bitmap):

(Sorry I don't know why the font isn't working - cut and paste this into an APL section and it should read correctly).

 

/Mark

 

      Œvr 'bmpfn_print'
    ’ bmpfn_print ;fn;orientation;x;head;bmwidth;bmheight;printer;nw;nh;horig;v
      orig;sourcefilename;bmpfilename;workfilename
[1]
[2]   fn„('onebmp' Œwi ':‘bmpfilename')
[3]   bmpfn_writebmp fn
[4]   bmpfn_storesize fn
[5]
[6]   head „ 200 readfile fn
[7]   head„(int head[gi bfoffbits])†head
[8]   bmwidth„width head
[9]   bmheight„height head
[10]  :if bmheight < bmwidth
[11]      orientation„'landscape'
[12]  :else
[13]      orientation„'portrait'
[14]  :endif
[15]  printer„'bmpobj_printer'
[16]  :if ~(›printer)¹'#' Œwi 'children'
[17]      x„printer Œwi 'Create' 'Printer'
[18]  :endif
[19]  x„printer Œwi 'orientation' orientation
[20]  x„printer Œwi 'paper' 269
[21]  x„printer Œwi 'PrintDlg'
[22]  :if 0 = 1½x
[23]      :return
[24]  :endif
[25]  (bmheight bmwidth) bmpfn_drawstretch (printer fn)
[26]  x„printer Œwi 'Close'
    ’

Œvr 'bmpfn_drawstretch'
    ’ hw bmpfn_drawstretch pfn;Œio;printer;filename;phdc;chdc;x;hbitmap;hzip;hr
      et;a;aa;dib;hbitmapa;hbitmapc;psize;ratio;y;wo;ho;wn;hn;size;margins;scal
      e;scaledmargins;s;m;bmheight;bmwidth;bmratio;prratio;xo;yo
[1]   Œio„0
[2]
[3]   (bmheight bmwidth)„hw
[4]   (printer filename)„pfn
[5]   phdc„printer Œwi 'hdc'
[6]   chdc„Œwcall 'CreateCompatibleDC' phdc
[7]   hbitmap„нprinter Œwi 'Draw' ('?Bitmap' filename)
[8]   hzip„Œwcall 'SelectObject' chdc hbitmap
[9]
[10]  s„1†printer Œwi 'scale'
[11]  :if bmheight>bmwidth
[12]      m„72×.25 .25 .25 ,11÷32
[13]  :else
[14]      m„72×.25, (11÷32), .25 .25
[15]  :endif
[16]  x„printer Œwi 'scale' 3
[17]  x„printer Œwi 'margin' m
[18]  x„printer Œwi 'scale' 5
[19]  margins„printer Œwi 'margin'
[20]  size„printer Œwi 'size'
[21]  psize„size-(+/margins[2 3]),+/margins[0 1]
[22]
[23]  bmratio„bmheight÷bmwidth
[24]  prratio„psize[0]÷psize[1]
[25]  :if bmratio>prratio     © crop the height
[26]      wo„bmwidth
[27]      ho„˜bmwidth×prratio
[28]      yo„˜.5×bmheight-ho
[29]      xo„0
[30]  :else
[31]      ho„bmheight
[32]      wo„˜bmheight÷prratio
[33]      yo„0
[34]      xo„˜.5×bmwidth-wo
[35]  :endif
[36]
[37]  ratio„˜/psize÷ho,wo
[38]  wn„˜ratio×wo
[39]  hn„˜ratio×ho
[40]  x„margins[0]
[41]  y„margins[2]
[42]
[43]  debug Œwcall 'StretchBlt' phdc x y wn hn chdc xo yo wo ho 'SRCCOPY'
[44]
[45]  hret„Œwcall 'SelectObject' chdc hzip
[46]  debug Œwcall 'DeleteObject' hbitmap
[47]
[48]  debug Œwcall 'DeleteDC' chdc
[49]  ©Œwcall 'EndPage' phdc
[50]  debug Œwcall 'EndDoc' phdc
[51]
    ’

 

 

 

 

     

davin.church
Problem printing bmp file
Posted: Wednesday, December 27, 2006 3:21 PM (EST)

Jeff,

 

Paint indicates the picture size at screen resolution, not printer resolution.  Your image needs to be sized for printer use (if you know what resolution to use), or dynamically adjust it like Mark says.  (You might also be interested in using the APL2000.Draw object to resize and/or print it.)

 

I don't know what you might do if you're putting it into a PDF file though, becase I don't know what facilities it has for adjusting image sizes at display time.

     

brent.hildebrand
Problem printing bmp file
Posted: Thursday, December 28, 2006 3:31 PM (EST)

The problem with the Draw method of []WI is that it does not scale bitmaps.  Another way to print scaled bitmaps is to use the APL2000's APLDraw object.  I print PDF files using the PDF995 print driver (www.pdf995.com).  I prefer pixels for the scale which works nice with APLDraw.  I create a printer object, and another form to hold the APLDraw object.  I draw the bitmap in the APLDraw object to scale, then use the XPrintOnHDC method of APLDraw to put the image on my printer object.  An example, let say I want to print a bitmap as a PDF so that there is 1 inch of margin around the image.  I first create the printer object, scaled to pixels:

      'pr' Œwi 'Create' 'Printer' ('caption' 'PDF995 APL')('printername' 'PDF995')
pr
      'pr' Œwi 'Print' ' '

 

NOTE: a single space was sent to the printer to initialize the printer.  You may or may not need this depending on where you are in your printing process.

 

With 8.5" x 11" paper and 600 DPI, the page size is this:

 

      'pr' Œwi 'size'
6600 5100

 

So an image that filled the page with 1" margin would be 5400 by 3900 pixels.

 

So create an APLDraw object with those dimensions and then add the bitmap called to fill the object.  Then, put the APLDraw image on the printer.

 

'fm' Œwi 'Create' 'Form'
'fm.draw' Œwi 'Create' 'APL2000.Draw'
'fm.draw' Œwi 'xImageWidth' 3900
'fm.draw' Œwi 'xImageHeight' 5400
'fm.draw' Œwi 'XDrawImage' 'myfile.bmp' 0 0 5400 3900
'fm.draw' Œwi 'XDrawImage' 'myfile.bmp' 0 0 5400 3900
'fm.draw' Œwi 'XDrawOnHDC' ('pr' Œwi 'hdc') 600 600

 

Now close the printer to print the page, on save it to a file in the case of the PDF.

 

'pr' Œwi 'Delete'

 

You can use APLDraw to scale the bitmap, then save the bitmap to a file, then use that file in the []WI  Draw method to put the image in the PDF and my experience is that the results look exactly the same.  The difference is that the resultant PDF file will be huge, over a megabyte, while using the DrawOnHDC method will produce a PDF that is small, depending on the image complexity, as low a 8KB, 100 fold less in size! 

     

Support
Problem printing bmp file
Posted: Saturday, December 30, 2006 9:56 PM (EST)

> 'pr' Œwi 'Print' ' '
 

> NOTE: a single space was sent to the printer to initialize the printer.  You may or may

> not need this depending on where you are in your printing process.

 

In version 6.2 and later, you can replace this step with 'pr' Œwi 'dirty' 1.  The dirty property specifies whether the page was printed to and thereby eliminates sending a blank space to the page.  Refer to Chapter 2 in the Windows Reference Manual for more information on this property.

 

APL2000 Support

     

brent.hildebrand
Problem printing bmp file
Posted: Sunday, December 31, 2006 1:35 PM (EST)
Neat! ("dirty" is neat!) I missed that one.

     



APL2000 Official Web Site

To err is human, but when the eraser wears out ahead of the pencil, you're overdoing it.
- Josh Jenkins

APLDN Home   |    |  Events   |  Trainings   |  APL Books   |  APLDN Links   |    |  Discussion Groups   |    |  Downloads   |  Articles   |  Library   |  Learning Tools   |  APLDN User IO   |  APL2000.com   |