How to adj. a Image (Res.) using <Loadimage> SOLVED !

How to adj. a Image (Res.) using <Loadimage> SOLVED !

Postby ukoenig » Tue Jan 22, 2013 2:20 pm

Hello,

2 functions :

1.)
NOT transparent ! bur resizing works ( adjusted to resource ).

REDEFINE IMAGE oIMG1 OF oDlg FILENAME NIL ;
ID 110 PIXEL BORDER
oIMG1:cTooltip := "Image 1l"
oIMG1:bPainted := { |hDC| ( cSize1 := DRAW_IMG(oIMG1, hDC, cImage0, ;
oSay2, oSay4, cSize1, cSize2 ), oSay1:Refresh(), oSay2:Refresh() ) }

FUNCTION DRAW_IMG( oImage, hDC, cImage, oSay2, oSay4, cSize1 )
LOCAL oImg, aRect[4], nFactor1, nFactor2, aRect

DEFINE IMAGE oImg FILENAME c_path1 + cImage

aRect := GETCLIENTRECT( oImage:hWnd )
// MsgAlert( aRect[4] ) // Resource Width
// MsgAlert( aRect[3] ) // Resource Height

nFactor1 := aRect[4] / oImg:nWidth
nFactor2 := aRect[3] / oImg:nHeight
cSize := ALLTRIM(STR(oImg:nWidth)) + "x" + ALLTRIM(STR(oImg:nHeight)) + ;
" Resize-Factor : W = " + ALLTRIM(STR(nFactor1)) + " H = " + ALLTRIM(STR(nFactor2))
IF nFactor1 > 1 .and. nFactor2 > 1
PalBmpDraw( hDC, 0, 0, oImg:hBitmap, ,oImg:nWidth, oImg:nHeight )
cSize1 := "Width : " + ALLTRIM(STR(oImg:nWidth)) + ;
" / Height : " + ALLTRIM(STR(oImg:nHeight))
ENDIF
RETURN( cSize )


Image

I need a Function for resizing like sample 1 !
PalBmpdraw dosn't show transparent PNG's


2.)
REDEFINE IMAGE oIMG1 OF oDlg FILENAME NIL ;
ID 110 PIXEL BORDER
oIMG1:cTooltip := "Image 1l"
oIMG1:LoadImage( , c_path1 + cImage0 )

Transparent but not adjusted to resource !

Image

Best Regards
Uwe :?:
Last edited by ukoenig on Tue Jan 22, 2013 8:03 pm, edited 1 time in total.
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: How to adj. a Image (Res.) using <Loadimage> SOLVED !

Postby ukoenig » Tue Jan 22, 2013 7:59 pm

SOLVED !!!

any combinations of NON transparent with alphablended BMP / PNG

Image

A combination of using
ABPaint and
PalBmpDraw is needed.
For using ABPaint, You have to detect the Alpha-Image
with IF lAlpha = .T.

Code: Select all  Expand view

// Appl.-path
// c_path := cFilePath(GetModuleFileName( GetInstance() ) )
// Image-path
// c_path1 := c_path + "IMAGES\"

REDEFINE IMAGE oIMG1 OF oDlg FILENAME NIL ;
ID  110 PIXEL BORDER
oIMG1:cTooltip := "Image 1"
oIMG1:bPainted := { |hDC| ( cSize1 := DRAW_IMG(oIMG1, hDC, cImage0 ), ;
                                              oSay1:Refresh(), oSay2:Refresh() ) }

// Image-name
//----------------
REDEFINE SAY oSay1 PROMPT cImage0 ID 120 OF oDlg UPDATE
oSay1:SetColor( 0 )
oSay1:SetFont( oFont1 )

//Size and Resize-factor information
// -----------------------------------------
REDEFINE SAY oSay2 PROMPT cSize1 ID 130 OF oDlg UPDATE
oSay2:SetColor( 128 )
oSay2:SetFont( oFont1 )
..
..

FUNCTION DRAW_IMG( oImage, hDC, cImage )
LOCAL oImg, oImg0, nFactor1, nFactor2, aRect, nWidth, nHeight

aRect := GETCLIENTRECT( oImage:hWnd )
// MsgAlert( aRect[4] ) // Resource Width
// MsgAlert( aRect[3] ) // Resource Height

IF FILE( c_path1 + cImage )
    DEFINE IMAGE oImg FILENAME c_path1 + cImage

    nFactor1 := aRect[4] / oImg:nWidth  
    nFactor2 := aRect[3] / oImg:nHeight
    cSize := ALLTRIM(STR(oImg:nWidth)) + "x" + ALLTRIM(STR(oImg:nHeight)) + ;
                   "   Resize-Factor : W = " + ALLTRIM(STR(nFactor1)) + " H = " + ALLTRIM(STR(nFactor2))
    nWidth := oImg:nWidth
    nHeight := oImg:nHeight

    oImg0 := FILoadImg( c_path1 + cImage )
    lAlpha := HasAlpha( oImg0 )
   
    IF nFactor1 > 1 .and. nFactor2 > 1
        IF lAlpha = .T.
            ABPaint( hDC, 0, 0, oImg0, 255 )
            DeleteObject( oImg0 )
        ELSE
            PalBmpDraw( hDC, 0, 0, oImg:hBitmap, ,oImg:nWidth, oImg:nHeight )
        ENDIF
    ENDIF
    IF nFactor1 < 1 .and. nFactor2 < 1
        IF nFactor1 < nFactor2 // Width-factor > Height-factor  
            IF lAlpha = .T.
                DeleteObject( oImg )
                oImg := ResizeImg( oImg0, aRect[4], nHeight * nFactor1 )
                ABPaint( hDC, 0, 0, oImg, 255 )
            ELSE
                PalBmpDraw( hDC, 0, 0, oImg:hBitmap, ,aRect[4], oImg:nHeight * nFactor1 )
            ENDIF
        ELSE // Width-factor < Height-factor  
            IF lAlpha = .T.
                DeleteObject( oImg )
                oImg := ResizeImg( oImg0, oImg:nWidth * nFactor2, aRect[3] )
                ABPaint( hDC, 0, 0, oImg, 255 )
            ELSE
                PalBmpDraw( hDC, 0, 0, oImg:hBitmap, ,oImg:nWidth * nFactor2, aRect[3] )  
            ENDIF
        ENDIF
        // MsgAlert( "True 2" )
    ENDIF
    IF nFactor1 < 1 .and. nFactor2 > 1
        IF lAlpha = .T.
            DeleteObject( oImg )
            oImg := ResizeImg( oImg0, aRect[4], nHeight * nFactor1 )
            ABPaint( hDC, 0, 0, oImg, 255 )
        ELSE
            PalBmpDraw( hDC, 0, 0, oImg:hBitmap, ,aRect[4], oImg:nHeight * nFactor1 )
        ENDIF
    ENDIF
    IF nFactor1 > 1 .and. nFactor2 < 1
        IF lAlpha = .T.
            DeleteObject( oImg )
            oImg := ResizeImg( oImg0, nWidth * nFactor2, aRect[3] )
            ABPaint( hDC, 0, 0, oImg, 255 )
        ELSE
            PalBmpDraw( hDC, 0, 0, oImg:hBitmap, , oImg:nWidth * nFactor2, aRect[3] )
        ENDIF
     ENDIF
     DeleteObject( oImg )
ELSE
    MsgAlert( "File : " + cImage + CRLF + ;
            "does not exist" + CRLF + ;
                "to show Image !", "ATTENTION" )
ENDIF

RETURN( cSize )
 


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: Google [Bot] and 116 guests