Rectangle as bitmap

Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Rectangle as bitmap

Post 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 ?
User avatar
Antonio Linares
Site Admin
Posts: 42662
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 69 times
Been thanked: 96 times
Contact:

Re: Rectangle as bitmap

Post 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 nilfunction ShowPopup( nRow, nCol, oGrp )   local oPopup   MENU oPopup POPUP       MENUITEM "Save as BMP" ACTION MsgInfo( "ok" )   ENDMENU    ACTIVATE POPUP oPopup WINDOW oGrp AT nRow, nColreturn nil


Next is to create and save the bitmap
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42662
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 69 times
Been thanked: 96 times
Contact:

Re: Rectangle as bitmap

Post 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 nilfunction 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, nColreturn nil    
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Post by Natter »

Thank you, Antonio ! So I can use this solution not only for Group, but also for an arbitrary-form rectangle ?
User avatar
Antonio Linares
Site Admin
Posts: 42662
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 69 times
Been thanked: 96 times
Contact:

Re: Rectangle as bitmap

Post by Antonio Linares »

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

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 10733
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 11 times
Contact:

Re: Rectangle as bitmap

Post by nageswaragunupudi »

Code: Select all | Expand

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
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Post by Natter »

Rao, thank you for the clarification !
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Post 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 ?
User avatar
Antonio Linares
Site Admin
Posts: 42662
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 69 times
Been thanked: 96 times
Contact:

Re: Rectangle as bitmap

Post by Antonio Linares »

Yes, it should work the same
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Post by Natter »

Thank you, Antonio, this is what you need !
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Post 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/19fCRaLfk

What can I do wrong ?

FW 09.2006
Last edited by Natter on Thu Oct 07, 2021 10:27 am, edited 1 time in total.
User avatar
nageswaragunupudi
Posts: 10733
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 11 times
Contact:

Re: Rectangle as bitmap

Post by nageswaragunupudi »

but containing only the part of the control visible on the screen,.

Yes.
Regards

G. N. Rao.
Hyderabad, India
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Post by Natter »

And how can I get a picture of the entire control surface ?
User avatar
Antonio Linares
Site Admin
Posts: 42662
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 69 times
Been thanked: 96 times
Contact:

Re: Rectangle as bitmap

Post by Antonio Linares »

oControl:SaveToBmp("test.bmp")

Enviado desde mi SM-M325FV mediante Tapatalk
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Post by Natter »

Same result
Post Reply