Change color in a bmp

Re: Change color in a bmp

Postby ukoenig » Tue Mar 23, 2021 12:00 pm

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
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: Change color in a bmp

Postby Silvio.Falconi » Wed Mar 24, 2021 9:46 am

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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: Change color in a bmp

Postby Otto » Wed Mar 24, 2021 9:53 am

Silvio, I think I know where the problem is. Please post your code and the bitmap.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: Change color in a bmp

Postby Silvio.Falconi » Wed Mar 24, 2021 10:06 am

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 view
#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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: Change color in a bmp

Postby Otto » Wed Mar 24, 2021 10:28 am

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: Change color in a bmp

Postby Silvio.Falconi » Wed Mar 24, 2021 11:21 am

good
Image

but there are many white points also
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: Change color in a bmp

Postby Otto » Wed Mar 24, 2021 11:34 am

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: Change color in a bmp

Postby Silvio.Falconi » Wed Mar 24, 2021 12:03 pm

Otto,
I have many images , How I can clear all ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: Change color in a bmp

Postby Otto » Wed Mar 24, 2021 12:16 pm

Silvio, maybe Uwe knows a way?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: Change color in a bmp

Postby Otto » Thu Mar 25, 2021 8:05 am

Hello Silvio,
Try this online service:
https://onlinepngtools.com/change-png-color

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: Change color in a bmp

Postby Silvio.Falconi » Thu Mar 25, 2021 10:56 am

New release ( Otto see on your mail)

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 52 guests