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

hua
Posts: 1075
Joined: Fri Oct 28, 2005 2:27 am
Has thanked: 1 time
Been thanked: 1 time

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

Post 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
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

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

Post 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

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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.09 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
hua
Posts: 1075
Joined: Fri Oct 28, 2005 2:27 am
Has thanked: 1 time
Been thanked: 1 time

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

Post 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
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

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

Post 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
hua
Posts: 1075
Joined: Fri Oct 28, 2005 2:27 am
Has thanked: 1 time
Been thanked: 1 time

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

Post by hua »

Thanks James.

I'll give it a try and update you about it later
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
Posts: 1075
Joined: Fri Oct 28, 2005 2:27 am
Has thanked: 1 time
Been thanked: 1 time

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

Post 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.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

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

Post 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

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
Carlos Mora
Posts: 989
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

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

Post 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
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

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

Post by James Bott »

Carlos,

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

Regards,
James
hua
Posts: 1075
Joined: Fri Oct 28, 2005 2:27 am
Has thanked: 1 time
Been thanked: 1 time

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

Post by hua »

James,
Thanks for the reply.

James, Carlos, currently I implemented the technique this way

Code: Select all | Expand


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
 
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
User avatar
RAMESHBABU
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

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

Post 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
Last edited by RAMESHBABU on Thu Feb 17, 2011 7:15 am, edited 1 time in total.
User avatar
anserkk
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India
Has thanked: 2 times

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

Post 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
User avatar
RAMESHBABU
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

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

Post 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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

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

Post by nageswaragunupudi »

Dear Ramesh

Use imageshack.us
Regards

G. N. Rao.
Hyderabad, India
User avatar
RAMESHBABU
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

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

Post by RAMESHBABU »

Dear Mr.Rao.

Thank you very much.

- Ramesh
Post Reply