Page 1 of 1

To Antonio center image

PostPosted: Thu Jun 18, 2015 8:32 pm
by Silvio.Falconi
Can I use center method of Bitmaps to center an image into image area control ?
and how ?

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 8:59 am
by Antonio Linares
Silvio,

Please provide a small and self contained example, thanks

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 9:46 am
by Silvio.Falconi
Antonio,
the small sample run ok

Code: Select all  Expand view

# include "fivewin.ch"

function test()
local odlg,oImage
local oSay[7]
local obtn[1]

DEFINE DIALOG oDlg ;   //OF oParent
   TITLE "test"    ;
   SIZE  600, 600

 @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg

activate dialog odlg ;
on init  GetImage( oImage )

retur nil


 STATIC FUNCTION GetImage( oImage )

   local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

   if ! Empty( gcFile ) .and. File( gcFile )
      oImage:LoadBmp( gcFile )
       oImage:center()
   endif
return nil




when I use the same command on my app not run

Antonio, Remember the listview test ?
When I drop a file I insert an image on a control Image , it is on the top of the listview control

as you can see here

Image

if I use oImage:center() it move the" Image area" into center of dialog

but I wish move only the jpg of the file I dropped into center of "image area "

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 9:54 am
by Antonio Linares
You can use oImage:SetPos( nRow, nCol )

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 9:56 am
by cnavarro

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 1:43 pm
by Silvio.Falconi
cNavarro,

I use a dialog and I try to use

oAllegati:bResized := {|| nLTop := INT( ( ( oAllegati:nHeight ) / 2 ) - ( oImage:nHeight / 2 ) ), ;
nLLeft := INT( ( ( oAllegati:nWidth - 18 ) / 2 ) - ( oImage:nWidth / 2 ) ), ;
oImage:Move( nLTop, nLLeft, , , .T. ), ;
Rinfresca_oDlgallegati(oList,oAllegati ) }


but not run ok
the function I add Rinfresca_oDlgallegati(oList,oAllegati ) refresh some says and btns

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 1:56 pm
by cnavarro
Silvio.Falconi wrote:Antonio,
the small sample run ok

Code: Select all  Expand view

# include "fivewin.ch"

function test()
local odlg,oImage
local oSay[7]
local obtn[1]

DEFINE DIALOG oDlg ;   //OF oParent
   TITLE "test"    ;
   SIZE  600, 600

 @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg

activate dialog odlg ;
on init  GetImage( oImage )

retur nil


 STATIC FUNCTION GetImage( oImage )

   local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

   if ! Empty( gcFile ) .and. File( gcFile )
      oImage:LoadBmp( gcFile )
       oImage:center()
   endif
return nil




when I use the same command on my app not run

Antonio, Remember the listview test ?
When I drop a file I insert an image on a control Image , it is on the top of the listview control

as you can see here

Image

if I use oImage:center() it move the" Image area" into center of dialog

but I wish move only the jpg of the file I dropped into center of "image area "


Silvio, try

Code: Select all  Expand view

# include "fivewin.ch"

static nLTop
static nLLeft

function test()
local odlg,oImage
local oSay[7]
local obtn[1]

DEFINE DIALOG oDlg ;   //OF oParent
   TITLE "test"    ;
   SIZE  600, 600

 @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg

/*
// oAllegati -> oDlg
oAllegati:bResized := {|| nLTop := INT( ( ( oAllegati:nHeight ) / 2 ) - ( oImage:nHeight / 2 ) ), ;
nLLeft := INT( ( ( oAllegati:nWidth - 18 ) / 2 ) - ( oImage:nWidth / 2 ) ), ;
oImage:Move( nLTop, nLLeft, , , .T. ), ;
Rinfresca_oDlgallegati(oList,oAllegati ) }
*/

activate dialog odlg ;
on init  GetImage( oImage, oDlg )

retur nil


 STATIC FUNCTION GetImage( oImage, oDlg )

   local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

   if ! Empty( gcFile ) .and. File( gcFile )
      oImage:LoadBmp( gcFile )
      nLTop  := INT( ( ( oDlg:nHeight ) / 2 ) - ( oImage:nHeight / 2 ) )
      nLLeft := INT( ( ( oDlg:nWidth - 18 ) / 2 ) - ( oImage:nWidth / 2 ) )
     oImage:Move( nLTop, nLLeft, , , .T. )

//       oImage:center()
   endif
return nil

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 5:17 pm
by Silvio.Falconi
cNavarro
it run bad
but perhaps I undestood how make it

I tried to insert a Panel and on it the image and now is on the center

but I have prpblems with zoom

now I wish insert a scrollpanel instead of Panel because I need it if I zoom the image I must change the size of panel

but I have problems to use scrollpanel class into a dialog

please see the new topic at viewtopic.php?f=3&t=30932

Re: To Antonio center image

PostPosted: Fri Jun 19, 2015 9:26 pm
by cnavarro
Silvio,

The problem is that oImage resized according to the width and height of the image (file) to load.
To get what you want must "anchor" the oImage on another control
I think you can also have the effect you need

Code: Select all  Expand view

# include "fivewin.ch"

function test()
local odlg,oImage
local oSay[7]
local obtn[1]
Local oPnel

DEFINE DIALOG oDlg ;   //OF oParent
   TITLE "test"    ;
   SIZE  600, 600

 @ 2, 2 PANEL oPnel  SIZE 152, 152 OF oDlg
 @ 1, 1 IMAGE oImage SIZE 150, 150 OF oPnel PIXEL //NOBORDER
// @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg

activate dialog odlg ;
on init  GetImage( oImage, oPnel )

retur nil


 STATIC FUNCTION GetImage( oImage, oPnel )
Local nLTop
Local nLLeft
   local gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

   if ! Empty( gcFile ) .and. File( gcFile )
      oImage:LoadBmp( gcFile )
/*
// So it works well
      nLTop  := INT( ( ( oPnel:nHeight )/ 2 ) - ( nBmpHeight( oImage:hBitmap ) / 2 ) )
      nLLeft := INT( ( ( oPnel:nWidth ) / 2 ) - ( nBmpWidth( oImage:hBitmap ) / 2 ) )
     oImage:Move( nLTop, nLLeft, , , .T. )
*/

      oImage:center()
   endif
return nil

 

Re: To Antonio center image

PostPosted: Sat Jun 20, 2015 7:02 am
by Silvio.Falconi
yes of course I allready thinked it ( use tpanel class)

but your sample make error
Error description: Warning BASE/1004 Message not found: TPANEL:DEFCONTROL
you must create the panel with ON INIT

When I use Zoom effect dor the image I have problem because I must zoom also the tpanel

to make zoom also to tpanel we must use scrollpanel class


but scrollpanel panel has errors into dialog (it run good only on window)

I made a post to resolve this problem at viewtopic.php?f=3&t=30932