FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Rectangle as bitmap
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Rectangle as bitmap
Posted: Thu Sep 16, 2021 06:33 AM

Hi.

There is a dialog box with brush. I need to select a certain rectangle on this window and save it to a file as a bitmap. How to do it ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 11:43 AM
You may start it this way:

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

function Main()

   local oDlg, oGrp

   DEFINE DIALOG oDlg

   @ 1, 2 GROUP oGrp TO 6, 12 OF oDlg

   oGrp:bRClicked = { | nRow, nCol | ShowPopup( nRow, nCol, oGrp )}

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( oGrp:lDrag := .T., oGrp:CheckDots(), .T. ) 

return nil

function ShowPopup( nRow, nCol, oGrp )

   local oPopup

   MENU oPopup POPUP 
      MENUITEM "Save as BMP" ACTION MsgInfo( "ok" )
   ENDMENU 

   ACTIVATE POPUP oPopup WINDOW oGrp AT nRow, nCol

return nil


Next is to create and save the bitmap
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 11:53 AM
Enhanced version:

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

function Main()

   local oDlg, oGrp, oBrush

   DEFINE BRUSH oBrush FILENAME "c:\fwh\bitmaps\olga1.jpg"

   DEFINE DIALOG oDlg BRUSH oBrush SIZE 380, 400

   @ 1, 2 GROUP oGrp TO 6, 12 OF oDlg TRANSPARENT

   oGrp:bRClicked = { | nRow, nCol | ShowPopup( nRow, nCol, oGrp )}

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( oGrp:lDrag := .T., oGrp:CheckDots(), .T. ) 

return nil

function ShowPopup( nRow, nCol, oGrp )

   local oPopup

   MENU oPopup POPUP 
      MENUITEM "Save as BMP" ACTION oGrp:SaveToBmp( "test.bmp" )
   ENDMENU 

   ACTIVATE POPUP oPopup WINDOW oGrp AT nRow, nCol

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 12:05 PM

Thank you, Antonio ! So I can use this solution not only for Group, but also for an arbitrary-form rectangle ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 12:10 PM

Yes, it works for all kind of controls :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 01:18 PM
Code (fw): Select all Collapse
oDlg:SaveAsImage( cImageFile, aRect )


cImageFile can be .bmp, .jpg. ,png, etc.
aRect is the rectangle you want to crop and save. : { nTop, nLeft, nBottom, nRight }

This works with Window, Dialog or any Control, to crop a rectangle inside and save.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 02:02 PM

Rao, thank you for the clarification !

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Rectangle as bitmap
Posted: Tue Sep 21, 2021 06:07 AM

Will this scheme work if the dialog is larger than the monitor screen and, accordingly, the allocated rectangle is also larger than the monitor screen ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Rectangle as bitmap
Posted: Tue Sep 21, 2021 11:22 AM

Yes, it should work the same

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Rectangle as bitmap
Posted: Tue Sep 21, 2021 12:23 PM

Thank you, Antonio, this is what you need !

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 09:56 AM
I am trying to create a bmp file from an Activex control that is larger than the screen. I tried SaveToBmp(), SaveAsImage(). SaveWindow() . As a result, I get a bmp file of the appropriate size, but containing only the part of the control visible on the screen,.

https://cloud.mail.ru/public/ZDY3/19fCRaLfk

What can I do wrong ?

FW 09.2006
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:26 AM
but containing only the part of the control visible on the screen,.

Yes.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:30 AM

And how can I get a picture of the entire control surface ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:38 AM

oControl:SaveToBmp("test.bmp")

Enviado desde mi SM-M325FV mediante Tapatalk

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:44 AM

Same result