Page 1 of 1

A slider solution to adjust the color brightness ?

PostPosted: Thu Jun 03, 2021 7:25 pm
by ukoenig
Is there any easy slider-solution :?:

I created a function, but a little bit complicated.
The rest of the gradientpainter is working
Now I can select any background

maybe a calculation of the basic-RGB-value possible ?

Image

Image

I tested saving and loading the basic-gradientbitmap
next using the nrow position from the slider to get the color

FUNCTION GETCOLOR( nRow, nCol, oBmp )
LOCAL hDC := CreateCompatibleDC( oBmp:GetDC() )
LOCAL hBmp := ReadBitmap( 0, "Picker.bmp" ) // the basic gradient bmp
LOCAL hOldBmp := SelectObject( hDC, hBmp )
LOCAL nRGBColor := GetPixel( hDC, nCol, nRow )

SelectObject( hDC, hOldBmp )
DeleteObject( hBmp )
DeleteDC( hDC )
oBmp:ReleaseDC()

RETURN nRGBColor

best regards
Uwe :?:

Re: A slider solution to adjust the color brightness ?

PostPosted: Fri Jun 04, 2021 8:18 am
by Antonio Linares
Dear Uwe,

Your function code seems correct, is it working fine ?

Great work!

Re: A slider solution to adjust the color brightness ?

PostPosted: Fri Jun 04, 2021 9:08 am
by ukoenig
Dear Antonio,

now I'm using a double-solution for the color-adjustment
1. on image-click
2. optional on slider-position
the sliderposition is adjusted to the position on imageclick

the clickposition inside the slider must
be the same like inside the image :!:
the column-position is a given value
Pickvalues := PICK_COLOR( nSlidPos * 22, 8, oBmp ),

because the bitmap is painted is that needed :?:
( save and restore )

oBmp:SaveToBmp( "Picker.bmp" )
hBmp := ReadBitmap( 0, "Picker.Bmp" )

Image

Code: Select all  Expand view

#Include "FiveWin.ch"
#include "Slider.ch"

STATIC oDlg

// ---------------------------

FUNCTION Main()
LOCAL oBmp, oSlider, nSlidPos, oCGet1, oCGet2, oCSay, nPickcolor, cPickcolor
LOCAL oFont, oPos, Pickvalues, cGrdCol, nPos, nGrdCol := 255 // RED

DEFINE FONT oFont NAME "Tahoma" SIZE 0, -16 BOLD

DEFINE DIALOG oDlg TITLE "Testing colorchange " + FWVERSION ;
FROM 1, 1 TO 430, 300 PIXEL

nPos := 0.5

cGrdCol := "nRGB( " + ALLTRIM(STR(nRGBRed( 255 ))) + ", " + ;
                ALLTRIM(STR(nRGBGreen( 255 ))) + ", " + ;
                ALLTRIM(STR(nRGBBlue( 255 ))) + " )"

@ 145, 45 SAY oCSay PROMPT "           " OF oDlg SIZE 60, 12  PIXEL FONT oFont  BORDER UPDATE
oCSay:SetColor( 0, nGrdCol )
@ 160, 45 GET oCGet1 VAR nGrdCol  SIZE 60, 10  PICTURE "99999999" OF oDlg  FONT oFont PIXEL UPDATE
@ 173, 45 GET oCGet2 VAR cGrdCol  SIZE 85, 10  OF oDlg FONT oFont  PIXEL UPDATE

@ 68, 95 SAY oPos PROMPT nPos OF oDlg SIZE 25, 12  PIXEL FONT oFont  BORDER UPDATE

@ 15, 45 BITMAP oBmp FILENAME NIL SIZE 25, 115 OF oDlg  ;
PIXEL  ADJUST BORDER UPDATE
oBmp:bPainted := { |hDC| DRAW_BMP( hDC, oBmp, nGrdCol ) }
oBmp:bLClicked := { | nRow, nCol | nPos := nRow / 220, oPos:Refresh(), ;
                                                           oBmp:SaveToBmp( "Picker.bmp" ), ;
                                                           Pickvalues := PICK_COLOR( nRow, nCol, oBmp, nPos ), ;
                               nGrdCol := Pickvalues[1], ;  
                               cGrdCol := Pickvalues[2], ;
                                           oCSay:SetColor( 0, nGrdCol ), oCSay:Refresh(), ;
                                           oCGet1:Refresh(), oCGet2:Refresh(), ;
                               oSlider:Set( nRow / 22 ), oSlider:Refresh() }



nSlidPos := 5
// MsgAlert( nSlidPos[1], "Slider-Row" ) , ; // 110 = 5 x 22
@ 10, 70 SLIDER oSlider VAR nSlidPos OF oDlg ;
            VERTICAL ;
            RANGE 0, 10 ;
            COLORS CLR_RED, 12632256, CLR_CYAN ;
            MARKS 20 ;
            SIZE 18, 125 PIXEL UPDATE ;
            ON CHANGE ( nPos := nSlidPos / 10, oPos:Refresh(), ;
                                   oBmp:SaveToBmp( "Picker.bmp" ), ;
                                       Pickvalues := PICK_COLOR( nSlidPos * 22, 8, oBmp, nPos ), ;
                                       nGrdCol := Pickvalues[1], ;  
                                       cGrdCol := Pickvalues[2], ;
                       oCSay:SetColor( 0, nGrdCol ), oCSay:Refresh(), ;
                       oCGet1:Refresh(), oCGet2:Refresh() )

@ 195, 90 BTNBMP PROMPT "&EXIT"  SIZE 50, 15  PIXEL 2007;
 TOP ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED

oFont:End()

RETURN NIL

//------------- BMP-Brush -----------

FUNCTION DRAW_BMP( hDC, oBitmap, nColor )
LOCAL oBMPBrush, aGrad
LOCAL aRect := GETCLIENTRECT( oBitmap:hWnd )

aGrad := { { .5, CLR_WHITE, nColor }, { .5, nColor, CLR_BLACK } }

DEFINE BRUSH oBMPBrush ;
COLOR GradientFill( hDC,  0, 0, aRect[3], aRect[4], aGrad,  .T. ) // .T: = Vertical
oBMPBrush:End()

RETURN( NIL )

//---------

FUNCTION PICK_COLOR( nRow, nCol, oBmp, nPos )
LOCAL hDC := CreateCompatibleDC( oBmp:GetDC() )
LOCAL hBmp, nColor, hOldBmp, aValues[4]

hBmp        := ReadBitmap( 0, "Picker.Bmp" )
hOldBmp     := SelectObject( hDC, hBmp )

aValues[1]  := GetPixel( hDC, nCol, nRow )
IF nPos = 0
    aValues[1] := 16777215 // white
ENDIF
IF nPos = 1
    aValues[1] := 0 // black
ENDIF
SelectObject( hDC, hOldBmp )
DeleteObject( hBmp )
DeleteDC( hDC )
oBmp:ReleaseDC()

nRed    := nRGBRed( aValues[1] )
nGreen  := nRGBGreen(aValues[1] )
nBlue   := nRGBBlue( aValues[1] )
 
aValues[2]   := "nRGB( " + ALLTRIM(STR(nRed)) + ", " + ;
                ALLTRIM(STR(nGreen)) + ", " + ;
                ALLTRIM(STR(nBlue)) + " )"

//MsgAlert( nRow, "Img-Row" ) // 110 = 0.5

RETURN aValues
 


regards
Uwe :D