local hDC := oBmp:GetDC()
for nRow = 0 to oBmp:nHeigth() - 1
for nCol = 0 to oBmp:nWidth() - 1
if GetPixel( hDC, nRow, nCol ) == nClrToReplace
SetPixel( hDC, nRow, nCol, nClrNew )
endif
next
next
oBmp:ReleaseDC()
Use Windows GDI functions FloodFill() or ExtFloodFill().
Natter wrote:1, Get hDC.
2. Read pixels around the coordinates of the mouse cursor.
3. Determine that it is a white color and change it.
Only it's a long time.
You can specify the polygon with the corresponding color yourself
Function test()
local cFile:="a.jpg"
local cColori:="colori.bmp"
local oDlg,oBmp,oImg
local nColor:= 1,oColor
local hdc
DEFINE CURSOR oHand HAND
DEFINE dialog oDlg size 600,600
@ 4,1 XIMAGE oImg filename cFile SIZE 200,200 OF oDlg
@ 220,1 XIMAGE oBmp filename cColori SIZE 200,20 OF oDlg
@ 4, 220 get oColor var ncolor size 20,30 pixel COLOR ncolor,ncolor UPDATE
oBmp:oCursor = oHand
oBmp:bLClicked = { | nRow, nCol | (GetColor( nRow, nCol, oBmp,@nColor ), Msginfo(nColor), oColor:refresh() ) }
activate dialog oDlg
return nil
//--------------------------------------------------------------//
function GetColor( nRow, nCol, oBmp,nColor )
local hDC := oBmp:GetDC()
nColor := GetPixel( hDC, nCol, nRow )
DeleteDC( hDC )
oBmp:ReleaseDC()
return nil
//----------------------------------------------------//
FUNCTION MAIN()
local cFile:="a.bmp"
local cColori:="colori.png"
local oDlg,oBmp,oImg
local nColor := 0, oColor
local hdc, nPickRow := 0, nPickCol := 0
local oSay1, oSay2, oSay3, oFont
DEFINE CURSOR oHand HAND
DEFINE FONT oFont NAME "Verdanal" SIZE 0, -12 BOLD
DEFINE dialog oDlg size 520, 520
@ 4,1 XIMAGE oImg filename cFile SIZE 200,200 OF oDlg
oImg:oCursor := oHand
oImg:bPainted := < |hDC|
FLOODFILL( nPickRow, nPickCol, nColor )
// FILLCOLOR( hDC, oImg, nPickRow, nPickCol, nColor )
oSay1:Refresh()
oSay2:Refresh()
oSay3:Refresh()
RETURN NIL
>
oImg:bLClicked := { | nRow, nCol | nPickRow := nRow, nPickCol := nCol, oImg:refresh() }
@ 220,1 XIMAGE oBmp filename cColori SIZE 180,20 OF oDlg
@ 220, 183 get oColor var ncolor size 20, 20 pixel COLOR nColor, nColor UPDATE
@ 190, 210 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() ) }
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( hDC, oImg, nRow, nCol, nColor )
//MsgAlert( nRow, "Row" )
//MsgAlert( nCol, "Column" )
//MsgAlert( nColor, "Color" )
//ExtFloodFill( hDC, nRow, nCol, ncolor, 1 )
FloodFill( nRow, nCol, nColor )
RETURN NIL
Use Windows GDI functions FloodFill() or ExtFloodFill().
for the first time it takes the color but does not refresh the get,
the second time and after the color is always -1 why?
25, 10 BITMAP oBmp RESOURCE "CARTINA" OF oDlg UPDATE PIXEL SIZE 127, 179 NOBORDER TRANSPARENT
oBmp:bPainted := { |hDC| If( Empty( oBrw:oTreeItem:Cargo[ 5 ] ), nil, ;
FloodFill( hDC, oBrw:oTreeItem:Cargo[ 5 ], oBrw:oTreeItem:Cargo[ 6 ], nil, CLR_RED ) ) }
ukoenig wrote:Silvio,
regards
Uwe
#include "fivewin.ch"
FUNCTION MAIN()
local cFile:="a.bmp"
local cColori:="colori.png"
local oDlg,oBmp,oImg
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 520, 520
@ 4,1 XIMAGE oImg filename cFile SIZE 200,200 OF oDlg
oImg:oCursor := oHand
oImg:bPainted := < |hDC|
oSay1:Refresh()
oSay2:Refresh()
oSay3:Refresh()
RETURN NIL
>
@ 220,1 XIMAGE oBmp filename cColori SIZE 180,20 OF oDlg
@ 220, 183 get oColor var ncolor size 20, 20 pixel COLOR nColor, nColor UPDATE
@ 190, 210 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()
FloodFill( hDC, nRow, nCol, nil,nColor )
oImg:ReleaseDC()
RETURN NIL
//----------------------
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 117 guests