Page 1 of 2

What's the right technique using oPrn:SayBitmap()?

PostPosted: Tue Jan 26, 2010 4:13 am
by hua
Recently, I tried using oPrn:SayBitmap() to print a bitmap. After adjusting the width and height passed to :SayBitmap(), I got a look that I'm satisfied with during preview. For testing sake, I changed the printer from an inkjet to a dot-matrix and to my horror the bitmap has become very big.

Obviously I'm missing something here. What's the right technique to have the same look, irregardless of the printer that is in use?

TIA

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Tue Jan 26, 2010 9:43 am
by driessen
The width and height of the bitmap can change from one printer to another.

The code I use is :
Code: Select all  Expand view
oPrn:SayBitMap(0,0,"TEST.BMP",cWidth,cHeight)
This code is working fine here.

You must make the width and height variable if you want to use different printers.

Good luck.

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Tue Jan 26, 2010 12:19 pm
by hua
Thanks for the reply Michel.

Isn't there any logic that we can apply to get some sort of ratio so we wouldn't have to maintain a database of different width and height for different printers?

TIA

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Tue Jan 26, 2010 6:50 pm
by James Bott
Hua,

Maybe these are what you need.

nHeightPixels := Max( 0, ( nHeightInches * oPrn:nVertRes() / (oPrn:nVertSize() / 25.4 )) )
nWidthPixels := Max( 0, ( nWidthInches * oPrn:nHorzRes() / (oPrn:nHorzSize() / 25.4 )) )

Regards,
James

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Wed Jan 27, 2010 8:55 am
by hua
Thanks James.

I'll give it a try and update you about it later

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Wed Jun 30, 2010 5:34 am
by hua
James,
Works like a charm, thank you :)

I'd like to understand the logic though. So James, at your convenience, if you could elaborate a bit on the logics used?

Thank you again.

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Wed Jun 30, 2010 2:06 pm
by James Bott
Hua,

sayBitmap( nRow, nCol, cBitmap, nWidth, nHeight, nRaster )

nRow, nCol, nWidth, and nHeight are in pixels. Each printer may have a different resolution, i.e. pixels per inch, so you have to calculate these values for each printer.

Actually there is another issue. Each printer may have a different vertical and horizontal "offset." These are the sections of the page along the borders that the printer cannot print on. Like resolution, these offsets may be different for each printer.

I forgot to include these offsets in my calculations. However, you can use the built in method in TPrinter which does include these offsets. See the Inch2Pix( nRow, nCol) method of TPrinter. It returns an array {nRow, nCol}. So you could do something like:

Code: Select all  Expand view
oPrn:sayBitmap( oPrn:Inch2Pix(nRow, nCol):[1], ;
  oPrn:Inch2Pix(nRow, nCol):[2], ;
  cBitmap, ;
  oPrn:Inch2Pix(nWidth, nHeight):[1], ;
  oPrn:Inch2Pix(nWidth, nHeight):[2] )


Where nRow, nCol, nWidth, nHeight are all in inches.

There are also Cmtr2Pix() and Mmtr2Pix() methods if you prefer to use those.

Regards,
James

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Mon Jul 05, 2010 10:53 am
by Carlos Mora
Hi James,

let me make an observation: You are doing right NOT using oPrn:Inch2Pix(), because this function adjust coordinates only. The way you did is right.
If you want to use a method, check oPrn:SizeInch2Pix(), the last one in TPrinter (as off FWH9.04)

Best regards

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Mon Jul 05, 2010 5:50 pm
by James Bott
Carlos,

Thanks for pointing that out--I should have tested it.

Regards,
James

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Tue Jul 06, 2010 3:11 am
by hua
James,
Thanks for the reply.

James, Carlos, currently I implemented the technique this way

Code: Select all  Expand view

static nTRow, nTCol, nHeightPixels, nWidthPixels

function printForm()
    PRINTER oPrn PREVIEW NAME cTitl to zPrinter
    PrepImage(oPrn)
    .
    .
   oPrn:SayBitmap(nTRow, nTCol, "perkeso", nWidthPixels, nHeightPixels)
   .
   .
return nil

static function PrepImage(oPrn)
  // calculate the row, col to print and the bitmaps width and height in pixels
  local oBmp := TBitmap():define("perkeso") // to be used to get height to width ratio later
  local nInchWid := 0.826771654 // 21mm
  local nInchHgt

  nWidthPixels := Max( 0, ( nInchWid * oPrn:nHorzRes() / (oPrn:nHorzSize() / 25.4 )) )
  nInchHgt := nInchWid * oBmp:nHeight() / oBmp:nWidth()
  nHeightPixels := Max( 0, ( nInchHgt * oPrn:nVertRes() / (oPrn:nVertSize() / 25.4 )) )

  nTRow := 0.669291339 // in inches - 22mm
  nTCol := 0.354330709
  oPrn:Inch2Pix(@nTRow, @nTCol)

  oBmp:end()
return nil
 

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Wed Feb 16, 2011 5:54 pm
by RAMESHBABU
Hello Friends,

I am trying to print a Logo on a dull background image.
Both the graphics (Logo as well as the background) are .BMP files.

When I used oPrn:SayBitMap(....), The Logo BMP file is not printed
Transparent on the background. The Logo is printed with a white
square box on the dull background as shown here.

Image

Can anybody guide me how to print the Logo transparent on an
another BMP file.

Regards,

- Ramesh Babu P

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Thu Feb 17, 2011 4:41 am
by anserkk
Dear MR.Ramesh,

Did you try oPrn:SayImage() ? What about the Logo.Bmp ? Does it have an Alpha channel ?.

oPrn:SayImage( nRow, nCol, oImage, nWidth, nHeight, nRaster, lStretch, nAlphaLevel, nAlign )

This is just an idea

What I am suggesting is an alternative way. I am sure that this not the solution that you are looking for, but this trick may serve your purpose.

You have both the BMP files ie the Logo.Bmp and BackGround.Bmp
Use any graphic tools For eg. PixelFormer (Freeware) to place the Logo.BMP on the Background.Bmp and save this as a new file LogoWithBackGround.Bmp

Later you can use the LogoWithBackGround.Bmp as usual with oPn:SayBitmap

Regards
Anser

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Thu Feb 17, 2011 5:44 am
by RAMESHBABU
Dear Anser Bhai,

>>Does it have an Alpha channel ?.

No. It is a plain BMP file.

>>Use any graphic tools For eg. PixelFormer (Freeware) to place the Logo.BMP on the Background.Bmp and save this as a new file LogoWithBackGround.Bmp

If no solution is found, this is only the left out option.

BTW, previously I used to use HYPERUPLOAD.COM to publish images in our forum. Now that site is no more working. Can you suggest any alternative site ?

Regards to you,

- Ramesh Babu P

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Thu Feb 17, 2011 6:12 am
by nageswaragunupudi
Dear Ramesh

Use imageshack.us

Re: What's the right technique using oPrn:SayBitmap()?

PostPosted: Thu Feb 17, 2011 7:19 am
by RAMESHBABU
Dear Mr.Rao.

Thank you very much.

- Ramesh