Page 1 of 3
Rectangle as bitmap
Posted: Thu Sep 16, 2021 6:33 am
by Natter
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 ?
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 11:43 am
by Antonio Linares
You may start it this way:
Code: Select all | Expand
#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
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 11:53 am
by Antonio Linares
Enhanced version:
Code: Select all | Expand
#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
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 12:05 pm
by Natter
Thank you, Antonio ! So I can use this solution not only for Group, but also for an arbitrary-form rectangle ?
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 12:10 pm
by Antonio Linares
Yes, it works for all kind of controls

Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 1:18 pm
by nageswaragunupudi
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.
Re: Rectangle as bitmap
Posted: Thu Sep 16, 2021 2:02 pm
by Natter
Rao, thank you for the clarification !
Re: Rectangle as bitmap
Posted: Tue Sep 21, 2021 6:07 am
by Natter
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 ?
Re: Rectangle as bitmap
Posted: Tue Sep 21, 2021 11:22 am
by Antonio Linares
Yes, it should work the same
Re: Rectangle as bitmap
Posted: Tue Sep 21, 2021 12:23 pm
by Natter
Thank you, Antonio, this is what you need !
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 9:56 am
by Natter
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/19fCRaLfkWhat can I do wrong ?
FW 09.2006
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:26 am
by nageswaragunupudi
but containing only the part of the control visible on the screen,.
Yes.
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:30 am
by Natter
And how can I get a picture of the entire control surface ?
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:38 am
by Antonio Linares
oControl:SaveToBmp("test.bmp")
Enviado desde mi SM-M325FV mediante Tapatalk
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:44 am
by Natter
Same result