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
// 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() )
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 )
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 )
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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 47 guests