FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Printing an image.
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Printing an image.
Posted: Thu Aug 25, 2016 07:10 PM
Guys:

How can I print an image in 8.5" x 11" size (letter) ?
Code (fw): Select all Collapse
      oImg1:Print( , , , 06 )


I know that the
Code (fw): Select all Collapse
oImg1:Print( , , , n )
method prints the image and sizes it according to n. This requires a trial and error process. Can it be done in just one try ?


Thank you very much !
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Printing an image.
Posted: Thu Aug 25, 2016 09:23 PM
Please try
Code (fw): Select all Collapse
function PrnImage

   local oPrn
   local cImage   := "c:\fwh\bitmaps\olga1.jpg"

   PRINT oPrn PREVIEW
   PAGE

   @ 1, 1 PRINT TO oPrn IMAGE cImage SIZE 7,9 INCHES NOTRANSPARENT STRETCH

   ENDPAGE
   ENDPRINT

return nil


Regards



G. N. Rao.

Hyderabad, India
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: Printing an image.
Posted: Fri Aug 26, 2016 06:01 AM
Rao:

Thank you very much for your response, however I'm getting the following compilation error:
Code (fw): Select all Collapse
Error E0030  Syntax error "syntax error at '@'"


Offending line:
Code (fw): Select all Collapse
@ 1, 1 PRINT TO oPrn IMAGE cImage SIZE 7,9 INCHES NOTRANSPARENT STRETCH



I'm using FW 16.03, any ideas ?


Thank you very much !
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Printing an image.
Posted: Fri Aug 26, 2016 06:39 AM

FWH 16.03: Please use the method:

PrintImage( nRow, nCol, cImage, nWidth, nHeight, lStretch, nAlpha, lTransp, lGray ) // All units in pixels

Ex:
oPrn:PrintImage( 100,100, "c:\fwh\bitmaps\olga1.jpg", 5000,7000 )

Regards



G. N. Rao.

Hyderabad, India
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: Printing an image.
Posted: Fri Aug 26, 2016 07:42 AM

Rao:

Thank you for your help. How can I find out the pixel size of the full image and how many pixels does an 8.5" x 11" page has ?
Thank you very much my friend.

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Printing an image.
Posted: Fri Aug 26, 2016 04:41 PM

Gustavo,

The Image is adjusted to a given page-area.
Using small images there is a zoom-factor

look at Your post :

viewtopic.php?f=3t=32880p=193508#p193508

regards
Uwe :D

&&

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Printing an image.
Posted: Fri Aug 26, 2016 10:14 PM

Gustavo,

> How can I find out the pixel size of the full image

oImage:nWidth() and oImage:nHeight()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Printing an image.
Posted: Fri Aug 26, 2016 10:18 PM
> how many pixels does an 8.5" x 11" page

http://www.unitconversion.org/typography/inchs-to-pixels-y-conversion.html

See CLASS TPrinter METHOD Inch2Pix( nRow, nCol )
Code (fw): Select all Collapse
METHOD Inch2Pix( nRow, nCol ) CLASS TPrinter

   nRow = Max( 0, ( nRow * ::nVertRes() / (::nVertSize() / 25.4 ))-::nYoffset )
   nCol = Max( 0, ( nCol * ::nHorzRes() / (::nHorzSize() / 25.4 ))-::nXoffset )

return { nRow, nCol }
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Printing an image.
Posted: Wed Sep 07, 2016 05:04 PM
Antonio,

I created a easy to use File-label-section, my customer asked for.
Once the values are defined, only different text is needed.

the paper orientation is landscape
7 labels can be printed
The text-rows, the distance from left to the 1. label and the label-width is defined
The calculation to center the text works fine but the calculation ( pixel ) to center the images doesn*t work for any reason
and I had to use fixed tested values.

nRow = Max( 0, ( nRow * ::nVertRes() / (::nVertSize() / 25.4 ))-::nYoffset )
nCol = Max( 0, ( nCol * ::nHorzRes() / (::nHorzSize() / 25.4 ))-::nXoffset )


I will check :

// SizeInch2Pix is for converting width and height
METHOD SizeInch2Pix( nHeight, nWidth ) CLASS TPrinter
DEFAULT nWidth := 0, nHeight := 0
if nHeight <> 0
nHeight := Max( 0, ( nHeight * ::nVertRes() / ( ::nVertSize() / 25.4 ) ) )
endif
if nWidth <> 0
nWidth := Max( 0, ( nWidth * ::nHorzRes() / ( ::nHorzSize() / 25.4 ) ) )
endif
return { nWidth, nHeight }

defined values :

1. text-row = aODat[64]
left border to the 1. label = aODat[65]
2. text-row = aODat[66]
3. text-row = aODat[67]
4. text-row = aODat[68]
5. text-row = aODat[69]
label-width = aODat[70] // labels next to each other )
text centered YES / NO = aODat[74] ( images are allways shown centerd )
image YES / NO = aODat[75]
Image-top = aODat[76]
Image-size = aODat[77]

nILeft := 260 // used a fixed value

tested left border + dlabel-distance / 2 to calculate the center of the 1. label

nILeft := Max( 0, ( aODat[65] * oPRINT:nHorzRes() / (oPRINT:nHorzSize() / 25.4 )) - oPRINT:nXoffset ) + ; // left distance
Max( 0, ( ( aODat[70] * oPRINT:nHorzRes() / (oPRINT:nHorzSize() / 25.4 )) - oPRINT:nXoffset ) / 2 ) // label center

INPUT



PRINTPREVIEW





could the centered image-position be calculated ?

best regards
uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Printing an image.
Posted: Thu Sep 08, 2016 06:53 AM

Uwe,

> but the calculation ( pixel ) to center the images doesn*t work for any reason

How are you painting them ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Printing an image.
Posted: Thu Sep 08, 2016 02:00 PM
Antonio,

the complete print-function
I can use it, to create a standalone sample

The final result of the calculations ( text works fine )
( I still have to check the 1. image start-position < money.bmp > )



NOT the same size :

// Text-labelwidth OK
nLablWidth := aODat[70]

// Image-labelwidth to long
nImgWidth := Max( 0, ( aODat[70] * oPRINT:nHorzRes() / (oPRINT:nHorzSize() / 25.4 )) - oPRINT:nXoffset )


Code (fw): Select all Collapse
FUNCTION P_REPORT4( oMeter, oText, oDlg )
LOCAL aPoint 
LOCAL oPRINT, oFont1, oFont2, oFont3, oPen1
LOCAL nLinI, nColI, nLinF, nColF 
LOCAL nLablBord, nLablWidth, nImgTop, nImgBord, nImgWidth, nImgCent  
LOCAL I := 1, nTextLeft[7], nImgLeft, nTextPos 

PRINTER oPRINT ; // FROM USER  ;
PREVIEW  MODAL ;
NAME "Patientenliste drucken"

IF EMPTY( oPRINT:hDC )
      MsgStop ( "Drucker nicht bereit !" )
      RETURN(.f.)
ENDIF
IF aVal[180] = 2     // fix for report thumbnails
    TPreview():lListViewHide := .T.
ENDIF

DEFINE FONT oFont1 NAME "Arial" SIZE 0, -18 BOLD OF oPRINT
DEFINE FONT oFont2 NAME "Arial" SIZE 0, -18 OF oPRINT
DEFINE FONT oFont3 NAME "Arial" SIZE 0, -14 BOLD OF oPRINT

DEFINE PEN oPen1 WIDTH 12 OF oPRINT

// ----- TEXT ---------- 

// defined  0.5
nLablBord       := aODat[65]

// defined 4.1
nLablWidth  := aODat[70]

// start with left space
nTextPos        := nLablBord

// ----- IMAGE ( pixel ) --------

// defined 7.2 to be calculated to pixel 
nImgTop     := Max( 0, ( ( aODat[76] ) * oPRINT:nVertRes() / (oPRINT:nVertSize() / 25.4 )) - oPRINT:nYoffset )

// defined 0.5 to be calculated to pixel 
nImgBord        := Max( 0, ( aODat[65] * oPRINT:nHorzRes() / (oPRINT:nHorzSize() / 25.4 )) - oPRINT:nXoffset )

// defined 4.1 to be calculated to pixel 
nImgWidth       := Max( 0, ( aODat[70] * oPRINT:nHorzRes() / (oPRINT:nHorzSize() / 25.4 )) - oPRINT:nXoffset ) 

// defined 1. image-center 
nImgCent        := nImgBord + ( nImgWidth / 2 ) 

I := 1
FOR I := 1 TO 7
    nTextLeft[I] := nLablBord
NEXT

oPRINT:SetPage(9)   //  A4
IF aODat[72] = .T.
    oPRINT:SetPortrait()         
ELSE
    oPRINT:SetLandscape()    
ENDIF

PAGE

    I := 1
    X := 8

    FOR I := 1 TO 7 // define var-start-values of 7 labels
        IF I = 2
            X := 17 ( array-positions )
        ELSEIF I = 3
            X := 26 
        ELSEIF I = 4
            X := 35
        ELSEIF I = 5
            X := 44 
        ELSEIF I = 6
            X := 53 
        ELSEIF I = 7
            X := 62
        ENDIF
        // add label-width to position
        nTextPos += nLablWidth

        // add label-width to position ( pixel ) after 1. loop
        IF I > 1
            nImgCent += nImgWidth / 2           
        ENDIF

        // define if text-centered
        IF aODat[74] = .T.
            // Left textposition if centered ( Label-width - Text- width )
            nTextLeft[1] := nLablWidth  - ( aODat[70] - oPRINT:CmtrGetTextWidth( TRIM(aODat[X-7]), oFont1 ) ) / 2
            nTextLeft[2] := nLablWidth  - ( aODat[70] - oPRINT:CmtrGetTextWidth( TRIM(aODat[X-6]), oFont2 ) ) / 2
            nTextLeft[3] := nLablWidth  - ( aODat[70] - oPRINT:CmtrGetTextWidth( TRIM(DTOC(aODat[X-5])),oFont2 ) ) / 2   
            nTextLeft[4] := nLablWidth  - ( aODat[70] - oPRINT:CmtrGetTextWidth( TRIM(aODat[X-4]), oFont2 ) ) / 2
            nTextLeft[5] := nLablWidth  - ( aODat[70] - oPRINT:CmtrGetTextWidth( TRIM(aODat[X-3]), oFont3 ) ) / 2
            nTextLeft[6] := nLablWidth  - ( aODat[70] - oPRINT:CmtrGetTextWidth( TRIM(aODat[X-2]), oFont3 ) ) / 2
            nTextLeft[7] := nLablWidth  - ( aODat[70] - oPRINT:CmtrGetTextWidth( TRIM(aODat[X-1]), oFont3 ) ) / 2
        ENDIF

        IF aODat[X] = .T. // selected label

            oPRINT:cmSay(   aODat[64],          nTextPos - nTextLeft[1], aODat[X-7],        oFont1,,CLR_BLACK,,PAD_LEFT  )  // 1
            oPRINT:cmSay(aODat[66],         nTextPos - nTextLeft[2], aODat[X-6],        oFont2,,CLR_BLACK,,PAD_LEFT  )  // 2

            IF aODat[71] = .T. // select line-painting           
                nFil := aODat[64] + 1.0 // Top 
                nCol :=  nLeft          // Left
                nTop := aODat[64] + 1.0 // Top  
                nBot := nLeft + 3.5     // Right
                aCoord1 := oPRINT:Cmtr2Pix( @nFil, @nCol )
                aCoord2 := oPRINT:Cmtr2Pix( @nTop, @nBot )
                oPRINT:Line ( nFil, nCol, nTop, nBot, oPen1 )        
            ENDIF   

            IF aODat[73] = .F. // print with date

                oPRINT:cmSay(aODat[67],     nTextPos - nTextLeft[3], TRIM(DTOC(aODat[X-5])),oFont2,,CLR_BLACK,,PAD_LEFT  )  // 3
                oPRINT:cmSay(aODat[68],     nTextPos - nTextLeft[4], aODat[X-4],        oFont2,,CLR_BLACK,,PAD_LEFT  )  // 4
                oPRINT:cmSay(aODat[69],     nTextPos - nTextLeft[5], aODat[X-3],        oFont3,,CLR_BLACK,,PAD_LEFT  )  // 5
                oPRINT:cmSay(aODat[69] + 0.8,   nTextPos - nTextLeft[6], aODat[X-2],        oFont3,,CLR_BLACK,,PAD_LEFT  )  // 6
                oPRINT:cmSay(aODat[69] + 1.6,   nTextPos - nTextLeft[7], aODat[X-1],        oFont3,,CLR_BLACK,,PAD_LEFT  )  // 7
            
            ELSE  // NO date

                oPRINT:cmSay(aODat[67],     nTextPos - nTextLeft[4], aODat[X-4],        oFont2,,CLR_BLACK,,PAD_LEFT  )
                oPRINT:cmSay(aODat[68],     nTextPos - nTextLeft[5], aODat[X-3],        oFont3,,CLR_BLACK,,PAD_LEFT  )
                oPRINT:cmSay(aODat[68] + 0.8,   nTextPos - nTextLeft[6], aODat[X-2],        oFont3,,CLR_BLACK,,PAD_LEFT  )
                oPRINT:cmSay(aODat[68] + 1.6,   nTextPos - nTextLeft[7], aODat[X-1],        oFont3,,CLR_BLACK,,PAD_LEFT  )
            
            ENDIF
    
            // ---------------- IMAGE ---------

            IF aODat[75] = .T. // print nImgCent - ( image-sze / 2 )
                IF aODat[77] = 500 // defined image-sizes
                    nImgLeft := nImgCent - 250 // 50 % minus 
                ENDIF
                IF aODat[77] = 600
                    nImgLeft := nImgCent - 300  
                ENDIF
                IF aODat[77] = 700
                    nImgLeft := nImgCent - 350  
                ENDIF
                IF aODat[77] = 800
                    nImgLeft := nImgCent - 400   
                ENDIF
                //           PrintImage( nRow,          nCol,     uImage, image-name     nWidth,     nHeight,   lStretch, nAlpha, lTransp, lGray )
                oPRINT:PrintImage( nImgTop,    nImgLeft, c_Pfad1 + aODat[X+1], aODat[77], aODat[77], .T.) // 9
            ENDIF

        ENDIF

    NEXT
 
ENDPAGE

ENDPRINT

oFont1:End()
oFont2:End()
oFont3:End()

RETURN( NIL )


regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Printing an image.
Posted: Sun Sep 18, 2016 03:32 PM
More tests trying to CALCULATE images centered

I tested the different functions of class PRINTER

before I added the needed values to center the images
on 7, 9 and 4 label-solutions
but impossible to convert the text-values to pixel-values
NO function returns the needed values

how to calculate the text-values to pixel ?

Text---to---Pixel ( used fixed tested values )
3.8----------896 ( needed results for image-distance )
3.1----------730
6.0----------1420

I created a extra image to adjust to centered



Code (fw): Select all Collapse
IF nStyle = 7 // Labels
   nILablWidth := 896  
   //          Text =>   1.6          3.8
   //                   nLablBord + ( nILablWidth / 2 ) - ( Imagesize / 2 )
   nImgLeft          := 310     +     448               -    aODat[99] / 2 // Pixel centered   
ENDIF
IF nStyle = 9 // Labels
   nILablWidth := 730
   //         Text =>   1.0           3.1
   //                  nLablBord + ( nILablWidth / 2 ) - ( Imagesize / 2 )
   nImgLeft         := 170     +     365               -   aODat[99] / 2 // Pixel centered  
ENDIF
IF nStyle = 4 // Labels
   nILablWidth := 1420 
   //        Text =>   3.0           6.0
   //                 nLablBord + ( nILablWidth / 2 ) - ( Imagesize / 2 ) 
   nImgLeft        := 630     +     710               -   aODat[99] / 2 // Pixel centered  
ENDIF
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Printing an image.
Posted: Sun Sep 18, 2016 04:46 PM

TPrinter object methods SayText() and PrintImage() automatically do all the calculations and center text (or multiline text) and images within given rectangle. Not only center, they can also optionally align the text/image to any of the 8 sides (4 sides and 4 corners of the given rectangle optionally. In the recent versions we can specify any units for the rectangle. There are also commands which make calling these methods easy.

If you still want to do all these calculations yourself, it is upto you.

Regards



G. N. Rao.

Hyderabad, India
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Printing an image.
Posted: Sun Sep 18, 2016 06:03 PM
Mr. Rao

all values are defined to print the text on a selected position
The image-positions ( values ) must be calculated in relation to the textposition
because printing images, pixel-values are needed.

regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Printing an image.
Posted: Mon Sep 19, 2016 09:06 AM
I got it working with all needed calculations to adjust the image-pos to lines or text-positions :-)
The image-positions can be adjusted to any margins lines and text.
This sample calculates everything CENTERED to A4 Landscape ( NO margin used )





// The A4 size print measures = 21.0 x 29.7cm, 8.27 x 11.69 inches

oPRINT:SetPage(9)
oPRINT:SetLandscape()
DEFINE FONT oFont1 NAME "Arial" SIZE 0, -26 BOLD OF oPRINT
DEFINE PEN oPen1 WIDTH 12 OF oPRINT


// Horizontal line centered
// -----------------------------
nRow := 10.5 // Top of horizontal line
nCol := 0 // Left
nTop := 10.5 // Top = 0.5 * A4-width ( 21.0 )
nBot := 29.7 // Right = A4-height ( 29.7 )
aCoord1 := oPRINT:Cmtr2Pix( @nRow, @nCol )
aCoord2 := oPRINT:Cmtr2Pix( @nTop, @nBot )


oPRINT:Line ( nRow, nCol, nTop, nBot, oPen1 )

// Vertical line centered
// --------------------------
nRow := 0 // Top of vertical line
nCol := 14.85 // Left = 0.5 * A4-height ( 29.7 )
nTop := 21.0 // Top = A4-width ( 21.0 )
nBot := 14.85 // Right = 0.5 * A4-height ( 29.7 )
aCoord1 := oPRINT:Cmtr2Pix( @nRow, @nCol )
aCoord2 := oPRINT:Cmtr2Pix( @nTop, @nBot )


oPRINT:Line ( nRow, nCol, nTop, nBot, oPen1 )

// Text centered with Text-top-adjustment
// ------------------------------------------------------
// 1 millimeter = 2.834645669291 point ( needed to calculate font-top )
nTextCentH := oPRINT:CmtrGetTextWidth( "AAA", oFont1 ) * 0.5 // 0.5 * textwidth
nFontHeight := oFont1:nHeight // points
// CmSay( nRow, nCol, cText, oFont, nWidth, nClrText, nBkMode, nPad, lO2A )


oPRINT:cmSay( 10.5 - oFont1:nHeight * 0.002834645669291, 14.85 - nTextCentH, "AAA", oFont1,,CLR_BLACK,,PAD_LEFT )
// MsgAlert( oFont1:nHeight, "Fontheight (216.67 points)" )

// Image centered using < Cmtr2Pix > to convert image-TOP / LEFT to pixel
// -------------------------------------------------------------------------------------------
nImgSize := 800
nRow := 10.5 // Top = 0.5 * A4-width
nCol := 14.85 // Left = 0.5 * A4-height
aCoord1 := oPRINT:Cmtr2Pix( @nRow, @nCol )
// PrintImage( nRow, nCol, uImage, nWidth, nHeight, lStretch, nAlpha, lTransp, lGray )


oPRINT:PrintImage( nRow - nImgSize / 2, nCol - nImgSize / 2, c_Pfad1 + "Test.bmp", nImgSize, nImgSize, .T.)

regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.