FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Strange situation
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Strange situation
Posted: Mon Oct 25, 2021 11:11 AM

Hi,

I need to paint over the space around the polygon in the picture - floodfill(). On the window, using the :line() method, I limit the green polygon. I make a bitmap of this window FW_MakeYourBitmap() and save it to the file FW_Save Image(). - my.bmp
1. When viewing .bmp in Windows the polygon frame has turned black
2. When opening .bmp in TBitmap or Timage the polygon frame turns white

How can I use floodfill() in this situation
if the border color is not clear.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange situation
Posted: Wed Oct 27, 2021 09:29 PM

Can we have a small sample?

Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Strange situation
Posted: Fri Oct 29, 2021 06:35 AM
Here is the map.bmp file:
https://dropmefiles.com.ua/ru/QwWY

Code (fw): Select all Collapse
#include "FiveWin.ch"

procedure Main
local siz:={575,659}
private oFrg

  DEFINE DIALOG oFrg FROM 0,0 TO siz[1], siz[2]  PIXEL ;
                         STYLE nOR(WS_POPUP, WS_BORDER)
  ACTIVATE DIALOG oFrg  ON INIT Frg_Ini()
return

procedure Frg_Ini
local oCl

*  @ 0,0 BITMAP oCl  OF oFrg  SIZE oFrg:nWidth, oFrg:nHeight  PIXEL  NOBORDER
  oCl:=TXImage():New(0, 0, oFrg:nWidth, oFrg:nHeight,, oFrg,, .F.)  
*  oCl:bPainted:={|hDc| FloodFill(hDc, 0, 0, CLR_BLACK, CLR_WHITE)}
  oCl:SetSource("map.bmp")
  oFrg:Center()
return
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Strange situation
Posted: Fri Oct 29, 2021 02:15 PM
What is wrong? Show with a picture please.

Code (fw): Select all Collapse
#Include "FiveWin.ch"

STATIC oDlg

FUNCTION Main()

   LOCAL aGrad
   LOCAL Siz := { 600, 800 }

   aGrad := { { 0.30, CLR_WHITE, CLR_WHITE },{ 0.50, CLR_WHITE, CLR_WHITE } }

   DEFINE DIALOG oDlg FROM 0, 0 TO Siz[1], Siz[2] PIXEL TRUEPIXEL ;
      STYLE nOR( WS_POPUP, WS_BORDER ) GRADIENT aGrad

   oDlg:lModal := .T.

   ACTIVATE DIALOG oDlg ON INIT Frg_Ini()

RETURN NIL

FUNCTION Frg_Ini()

   LOCAL oCl

   oCl := TXImage():New( 0, 0, oDlg:nWidth, oDlg:nHeight,, oDlg,, .F. )

   oCl:SetSource( "Map.bmp" )

   oDlg:Center()

RETURN NIL

// END


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange situation
Posted: Fri Oct 29, 2021 02:46 PM
karinha wrote:What is wrong? Show with a picture please.


He did not say there is anything wrong with the code.
He also sent "map.bmp". You can download and view the image.
His problem is floodfill.
We need to help him with that issue, which includes the issue of the color of the rectangle border.'
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange situation
Posted: Fri Oct 29, 2021 02:59 PM
Natter wrote:Hi,
1. When viewing .bmp in Windows the polygon frame has turned black
2. When opening .bmp in TBitmap or Timage the polygon frame turns white


That means the color used for the border is an alpha color/ transparent color.
We need the boundary in RGB color to use floodfill
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange situation
Posted: Fri Oct 29, 2021 03:17 PM
Natter wrote:Here is the map.bmp file:
https://dropmefiles.com.ua/ru/QwWY

Code (fw): Select all Collapse
#include "FiveWin.ch"

procedure Main
local siz:={575,659}
private oFrg

  DEFINE DIALOG oFrg FROM 0,0 TO siz[1], siz[2]  PIXEL ;
                         STYLE nOR(WS_POPUP, WS_BORDER)
  ACTIVATE DIALOG oFrg  ON INIT Frg_Ini()
return

procedure Frg_Ini
local oCl

*  @ 0,0 BITMAP oCl  OF oFrg  SIZE oFrg:nWidth, oFrg:nHeight  PIXEL  NOBORDER
  oCl:=TXImage():New(0, 0, oFrg:nWidth, oFrg:nHeight,, oFrg,, .F.)  
*  oCl:bPainted:={|hDc| FloodFill(hDc, 0, 0, CLR_BLACK, CLR_WHITE)}
  oCl:SetSource("map.bmp")
  oFrg:Center()
return


This entire code can be written as:
Code (fw): Select all Collapse
   DEFINE DIALOG oDlg SIZE 575,569 PIXEL TRUEPIXEL
   @ 0,0 XIMAGE oImg FILE ".\Natter\map.bmp" SIZE 0,0 OF oDlg NOBORDER
   ACTIVATE DIALOG oDlg CENTERED

with the same functionality.
As you said, you will see the border line in CLR_WHITE. That is because the background color of XImage control is CLR_WHITE.

Now add one line of code:
Code (fw): Select all Collapse
   DEFINE DIALOG oDlg SIZE 575,569 PIXEL TRUEPIXEL
   @ 0,0 XIMAGE oImg FILE ".\Natter\map.bmp" SIZE 0,0 OF oDlg NOBORDER
   oImg:SetColor( CLR_GRAY, CLR_HRED ) // Added
   ACTIVATE DIALOG oDlg CENTERED

Now you will see the border of the polygon in CLR_HRED.
You can test changing the background color in oImg:SetColor() and see that the border is shown in the background color of the control.

Now, this takes us back to drawing the polygon using Line() method in the first place.

The 4th and last param of FW_MakeYourBitmap() is lAlpha. Did you set this to .T. ?

Please wait for my next posting
Regards



G. N. Rao.

Hyderabad, India
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Strange situation
Posted: Fri Oct 29, 2021 03:55 PM
Excellent mister Nages.

Code (fw): Select all Collapse
#Include "FiveWin.ch"

STATIC oDlg

FUNCTION Main()

   LOCAL aGrad, oImg
   LOCAL Siz := { 600, 800 }

   aGrad := { { 0.30, CLR_WHITE, CLR_WHITE },{ 0.50, CLR_WHITE, CLR_WHITE } }

   DEFINE DIALOG oDlg FROM 0, 0 TO Siz[1], Siz[2] PIXEL TRUEPIXEL ;
      STYLE nOR( WS_POPUP, WS_BORDER ) GRADIENT aGrad

   @ 0,0 XIMAGE oImg FILE ".\map.bmp" SIZE 0,0 OF oDlg NOBORDER

   oImg:SetColor( CLR_GRAY, CLR_HRED ) // Added Mister Nages

   ACTIVATE DIALOG oDlg CENTERED

   //ON INIT Frg_Ini()

RETURN NIL

FUNCTION Frg_Ini()

   LOCAL oCl

   oCl := TXImage():New( 0, 0, oDlg:nWidth, oDlg:nHeight,, oDlg,, .F. )

   oCl:SetSource( "Map.bmp" )

   oDlg:Center()

RETURN NIL

// END


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange situation
Posted: Fri Oct 29, 2021 05:30 PM

Why Gradient, when we are using the entire area of the dialog? Is it not a waste of processor time?

Regards



G. N. Rao.

Hyderabad, India
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Strange situation
Posted: Fri Oct 29, 2021 05:39 PM

CLR_WHITE, CLR_WHITE -> hahahahahaha.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Strange situation
Posted: Fri Oct 29, 2021 05:42 PM
Mr. Natter

It appears that your map.bmps are all alpha bitmaps.
We need to start with non-alpha bitmaps.
Then everything works as expected.
I am giving here a sample using a non-alpha bitmap "sea.bmp" in \fwh\samples folder.

Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oWnd, aBmp, cBmp  := "c:\fwh\bitmaps\sea.bmp"
   local hNew

   hNew  := FW_MakeYourBitmap( 512, 384, <|hDC,w,h|
            local hPen  := CreatePen( PS_SOLID, 3, CLR_HRED )

            FW_DrawImage( hDC, cBmp, { 0,0,h,w } )
            MoveTo( hDC, 280,  50 )
            LineTo( hDC, 500, 300, hPen )
            LineTo( hDC,  30, 200, hPen )
            LineTo( hDC, 280,  50, hPen )
            FloodFill( hDC, 1, 1, CLR_HRED, CLR_HGREEN )

            DeleteObject( hPen )
            return nil
            >, .f. )

   FW_SaveImage( hNew, "new.bmp" )
   DeleteObject( hNew )

   XImage( "new.bmp" )

return nil


Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Strange situation
Posted: Fri Oct 29, 2021 06:52 PM

Thank you very much, Mr.Ro !
It seems that the problem is precisely that to draw the contour in using the on:Line() method of any color. As a result, I solved the problem - first using FloodFill, and then saving the fragment to a file (although I couldn't get a contour around the picture). I stopped at .png files because they are smaller and have a transparent background.
Thanks again !

Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Strange situation
Posted: Sat Oct 30, 2021 07:33 AM
hi,
although I couldn't get a contour around the picture

not sure if "SetWindowRgn" / "CombineRgn" API can help you

under MiniGUI Extended Version i can use
Code (fw): Select all Collapse
   SET REGION OF &name BITMAP &cSaveBmp TRANSPARENT COLOR RGB(252, 253, 252) TO RegionHandle
for a Splash-Screen which made all Transparent "Outside" Contour
greeting,

Jimmy

Continue the discussion