Page 2 of 2

Re: Change color in a bmp

Posted: Tue Mar 23, 2021 12:00 pm
by ukoenig
Silvio,

it seems to work now with BMP but I still noticed a problem using JPG :(
Just change these lines
xImage moving and zooming will delete selected colors :!:

@ 4,1 XIMAGE oImg filename cFile SIZE 200,200 OF oDlg
oImg:nUserControl := 0
oImg:oCursor := oHand
oImg:blClicked := { | nCol, nRow | nPickRow := nRow, nPickCol := nCol,;
FILLCOLOR(oImg, nPickRow, nPickCol, nColorSet ) }

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

FUNCTION FILLCOLOR( oImg, nRow, nCol, nColor )
LOCAL hDC := oImg:getDc()

FloodFill( hDC, nRow, nCol, nil, nColor )
oImg:SaveToBmp( "A.bmp" ) // save the last result :!:
oImg:ReleaseDC()

RETURN NIL

The original test-image

Image

The test

Image

sample from Otto

Image

regards
Uwe

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 9:46 am
by Silvio.Falconi
Uwe,

I made a test (using ExtFloodFill)

Image

I do not believe that in fivewin you cannot draw and color a drawing in a uniform way

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 9:53 am
by Otto
Silvio, I think I know where the problem is. Please post your code and the bitmap.
Best regards,
Otto

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 10:06 am
by Silvio.Falconi
Otto wrote:Silvio, I think I know where the problem is. Please post your code and the bitmap.
Best regards,
Otto


Otto,
this is the test

Code: Select all | Expand

#include "fivewin.ch"


    FUNCTION MAIN()

    local cColori:="colori.png"
    local cModello:="Modello.jpg"
    local cFile:="da_colorare.jpg"
    local oDlg,oBmp,oImg,oImgx
    local nColor := 0, oColor
    local hdc, nPickRow := 0, nPickCol := 0
    local oSay1, oSay2, oSay3, oFont
    local nColorSet:= 1
    DEFINE CURSOR oHand HAND
    DEFINE FONT oFont NAME "Verdanal" SIZE 0, -12 BOLD

    DEFINE dialog oDlg size 1100, 500

    @ 4,1 BITMAP oImgx filename cModello  SIZE 270,200 OF oDlg PIXEL NOBORDER
    @ 4,280 BITMAP oImg filename cFile  SIZE 260,200 OF oDlg  PIXEL NOBORDER
    @ 210,260 BITMAP oBmp filename cColori  SIZE 300,50 OF oDlg PIXEL NOBORDER



    oImg:oCursor := oHand
    oImg:bPainted := < |hDC|
        oSay1:Refresh()
        oSay2:Refresh()
        oSay3:Refresh()
    RETURN NIL
    >


    @ 210, 18 get oColor var ncolor size 20, 20 pixel  COLOR nColor, nColor UPDATE  NOBORDER
    @ 210, 100 say oSay0 PROMPT "Top, Left, color" size 60, 30 pixel  COLOR 0 FONT oFont UPDATE
    @ 200, 210 say oSay1 var nPickRow size 20, 20 pixel  COLOR 255 FONT oFont UPDATE
    @ 210, 210 say oSay2 var nPickCol size 20, 20 pixel  COLOR 255 FONT oFont UPDATE
    @ 220, 210 say oSay3 var nColor size 20, 20 pixel  COLOR 255 FONT oFont UPDATE

    oBmp:oCursor := oHand
    oBmp:bLClicked := { | nRow, nCol | ( ncolor := GETCOLOR( oBmp, nRow, nCol ), ;
                                                                oColor:SetColor(nColor, nColor), oColor:refresh(),nColorSet:=ncolor ) }

    oImg:blClicked := { | nRow, nCol | nPickRow := nRow, nPickCol := nCol,;
                        FILLCOLOR(oImg, nPickRow, nPickCol, nColorSet ) }



    ACTIVATE DIALOG oDlg CENTERED

    oFont:End()

    RETURN NIL

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

    FUNCTION GETCOLOR( oBmp, nRow, nCol )
    hDC := oBmp:GetDC()
    nColor := GetPixel( hDC, nCol, nRow )
    oBmp:ReleaseDC()
    RETURN nColor

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

  FUNCTION FILLCOLOR( oImg, nRow, nCol, nColor )
    local hDC:=oImg:getDc()
    LOCAL hBrush := CreateSolidBrush( nColor )
    LOCAL hOld := SelectObject(hDC, hBrush)
    ExtFloodFill(hDC, nCol, nRow,CLR_WHITE,2)
    SelectObject( hDC, hOld )
    DeleteObject( hBrush )
    //FloodFill( hDC, nCol, nRow, nil, nColor )
    oImg:ReleaseDC()
RETURN NIL
 

see your maiil

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 10:28 am
by Otto
Hello Silvio,
Great example.
ExtFloodFill only works on one color.
You have in your image at the border another color.

Image

Store your image as monochrome and all is working fine.

Image

Thank you for sharing.
Now I have an easter present for my grandchildren.

Best regards,
Otto

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 11:21 am
by Silvio.Falconi
good
Image

but there are many white points also

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 11:34 am
by Otto
Silvio, zoom your image, and you will see you have also RGB(204,204,204) inside the white spaces.
You must clean up the image.
Best regards,
Otto

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 12:03 pm
by Silvio.Falconi
Otto,
I have many images , How I can clear all ?

Re: Change color in a bmp

Posted: Wed Mar 24, 2021 12:16 pm
by Otto
Silvio, maybe Uwe knows a way?
Best regards,
Otto

Re: Change color in a bmp

Posted: Thu Mar 25, 2021 8:05 am
by Otto
Hello Silvio,
Try this online service:
https://onlinepngtools.com/change-png-color

Best regards,
Otto

Re: Change color in a bmp

Posted: Thu Mar 25, 2021 10:56 am
by Silvio.Falconi
New release ( Otto see on your mail)

Image