Fitting an Image in its Container

Fitting an Image in its Container

Postby arpipeline » Thu May 13, 2010 9:37 pm

I have created a resource with an image control. I am then using REDEFINE IMAGE ... FILENAME to load a JPG in the control. If the image is too big I want to fit it in its container. How do I do that?

TIA

ANDY
User avatar
arpipeline
 
Posts: 36
Joined: Thu Oct 26, 2006 5:23 pm
Location: United States

Re: Fitting an Image in its Container

Postby ukoenig » Thu May 13, 2010 10:31 pm

I think, it is the Solution, You are looking for :

Image

Code: Select all  Expand view

// Image defined inside a Folder-page
..
..
cIMAGE1 := "Test.jpg" // or Select with a Button

// < blanc > any small bmp-resource

REDEFINE BITMAP oBMP10  ID 170  ADJUST  RESOURCE "Blanc"  OF oFld:aDialogs[1]
oBMP10:bPainted := {|hDC| FO_IMAGE( oBMP10, cIMAGE1 }     
..
..
// ------------ IMAGE  ------------

FUNCTION FO_IMAGE( oBitmap, cBitmap)
Local oImage

// c_path := CURDRIVE() + ":\" + GETCURDIR()
cFile :=  c_path + "\" + ALLTRIM(cBitmap)

IF File( "
&cFile" ) // Test if the defined Image exists
   DEFINE IMAGE oImage FILENAME "
&cFile"
   aRect := GETCLIENTRECT( oBitmap:hWnd )
   nBmpWidth := oBitmap:nWidth()
   nBmpHeight := oBitmap:nHeight()
   PalBmpDraw( oBitmap:GETDC(), 0, 0, oImage:hBitmap, , aRect[4], aRect[3] )
   oBitmap:ReleaseDC()
ELSE
  IF !EMPTY(cBitmap)
      MsgAlert("
No Image defined, or File not found !","Error" )
   ENDIF
ENDIF

RETURN( NIL )

// --------------- Image-Selection with a Button and Resource-Refresh ---------

REDEFINE SAY oIMAGE1   VAR  cIMAGE1   ID 35 OF oFld:aDialogs[1] UPDATE

REDEFINE BTNBMP oBtn30 ID 30 OF oFld:aDialogs[1]  2007 ;
FILENAME c_path + "
\System\select.bmp" ; // define a Button-Bmp
TOP ;
PROMPT "
 &Image-Select  " ;
FONT oProgFont ;
ACTION ( cFilter := "
JPG (*.jpg)|*.jpg|" + ;
   "
BMP (*.bmp)|*.bmp|" + ;
   "
DIB   (*.dib)| *.dib|" + ;
   "
PCX   (*.pcx)| *.pcx|" + ;
   "
JPEG  (*.jpg)| *.jpg|" + ;
   "
PNG  (*.png)| *.png|" + ;
   "
GIF   (*.gif)| *.gif|" + ;
   "
TARGA (*.tga)| *.tga|" + ;
   "
RLE   (*.rle)| *.rle|", ;
   cNewBITM := cGetFile32( cFilter,"
Select a Picture" ,, "\" + CurDir() + c_Set + "\"), ;
   IIF( empty( cNewBITM ), MsgAlert( "
No file selected !","ATTENTION" ), NIL ), ;
   cIMAGE1 := cFileNoPath( cNewBITM ), oBMP10:Refresh(), oIMAGE1:Refresh() )


Maybe You want to show the original Size in Tiled-Mode ?
use FO_TILED( oBitmap,cBitmap ) instead of : FO_IMAGE( oBitmap, cBitmap)

Image

Code: Select all  Expand view

FUNCTION FO_TILED(  oBitmap,cBitmap )
LOCAL oImage, nRow := 0, nCol := 0, n

cFile := c_path + "\" + cBITMAP

IF FILE( "
&cFile" )
   DEFINE BITMAP oImage FILENAME "
&cFile"
   aRect := GETCLIENTRECT( oBitmap:hWnd )
   nHeight := oImage:nHeight
   nWidth := oImage:nWidth
   IF aRect[3] > 0
      DO WHILE nRow < aRect[3]
         nCol = 0
         DO WHILE nCol < aRect[4]
            PalBmpDraw( oBitmap:GETDC(), nRow, nCol, oImage:hBitmap )
            nCol += nHeight
         ENDDO
         nRow += nWidth
     ENDDO
  ELSE
    MsgAlert( "
Not possible to use Picture " + CRLF + ;
    cBitmap + CRLF + ;
    "
for TILED-selection !", "ATTENTION" )
  ENDIF
  oBitmap:ReleaseDC()
ELSE
   IF !EMPTY(cBitmap)
      MsgAlert( "
File : " + cBitmap + CRLF + ;
      "
does not exist" + CRLF + ;
      "
to create Background !", "ATTENTION" )
   ENDIF
ENDIF

RETURN( NIL )


using 2 Images :

Image

Code: Select all  Expand view

FUNCTION DRAW_TILED(  oBitmap,cBitmap1, cBitmap2 )
LOCAL oImage1, oImage2, nRow := 0, nCol := 0, n

cFile1 := c_path + "\" + cBITMAP1
cFile2 := c_path + "
\" + cBITMAP2

IF FILE( "
&cFile1" ) .and. FILE( "&cFile2" )
   DEFINE BITMAP oImage1 FILENAME "
&cFile1"
   DEFINE BITMAP oImage2 FILENAME "
&cFile2"

   aRect := GETCLIENTRECT( oBitmap:hWnd )
   nHeight1 := oImage1:nHeight
   nWidth1 := oImage1:nWidth
   nHeight2 := oImage2:nHeight
   nWidth2 := oImage2:nWidth
   IF aRect[3] > 0
      DO WHILE nRow < aRect[3]
         nCol = 0
         I := 1
         DO WHILE nCol < aRect[4]
            IF I = 1
               PalBmpDraw( oBitmap:GETDC(), nRow, nCol, oImage1:hBitmap )
               I := 0
               nCol += nHeight1
            ELSE
               PalBmpDraw( oBitmap:GETDC(), nRow, nCol, oImage2:hBitmap )
               I := 1
               nCol += nHeight2
            ENDIF
         ENDDO
         IF I = 1
            nRow += nWidth1
         ELSE
            nRow += nWidth2
         ENDIF
      ENDDO
   ELSE
      MsgAlert( "
Not possible to use Picture " + CRLF + ;
      cBitmap1 + "
and " + cBitmap2 + CRLF + ;
      "
for TILED-selection !", "ATTENTION" )
   ENDIF
   oBitmap:ReleaseDC()
ELSE
   IF !EMPTY(cBitmap1) .and. !EMPTY(cBitmap2)
      MsgAlert( "
File : " + cBitmap1 + " or " + cBitmap2 + CRLF + ;
           "
does not exist" + CRLF + ;
           "
to create Background !", "ATTENTION" )
   ENDIF
ENDIF

RETURN( NIL )


Best Regards
Uwe :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Fitting an Image in its Container

Postby Enrico Maria Giordano » Fri May 14, 2010 5:20 pm

arpipeline wrote:I have created a resource with an image control. I am then using REDEFINE IMAGE ... FILENAME to load a JPG in the control. If the image is too big I want to fit it in its container. How do I do that?

TIA

ANDY


Did you try ADJUST clause?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Fitting an Image in its Container

Postby ukoenig » Fri May 14, 2010 6:38 pm

Enrico
it works as well. The Difference :
The same Resource must show all Backgrounds : Colors, Brush, Image, Gradient, Circle and Style ( Bricks .. )

// works with Image
REDEFINE IMAGE oBMP10 ID 170 OF oFld:aDialogs[1] FILENAME c_path + c_Set + "\Fantasy2.jpg" ADJUST

My Solution for all Selections :

REDEFINE BITMAP oBMP10 ID 170 ADJUST RESOURCE "Blanc" OF oFld:aDialogs[1]
oBMP10:bPainted := {|hDC| ;
IIF( W_POS1 <= 10 .and. W_STYLE = 1, DRAW_GRAD( oBMP10, W_DIRECT, W_COLOR1, W_COLOR2, W_MOVE ), NIL ), ;
IIF( W_POS1 <= 10 .and. W_STYLE = 2, DRAW_COLOR( oBMP10, W_COLOR1 ), NIL ), ;
IIF( W_STYLE = 3, DRAW_IMG( oBMP10, W_IMAGE ), NIL ), ;
IIF( W_STYLE = 4 , DRAW_TILED( oBMP10, W_BRUSH ), NIL ), ;
IIF( W_STYLE = 5 , DRAW_CIRCL( oBMP10, W_CCOLOR1, W_CCOLOR2 ), NIL ), ;
IIF( W_STYLE = 6 , DRAW_STYLE( oBMP10, W_STYLE), NIL ) }


Best Regards
Uwe :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 105 guests