Rectangle as bitmap

Rectangle as bitmap

Postby Natter » Thu Sep 16, 2021 6: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 ?
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Postby Antonio Linares » Thu Sep 16, 2021 11:43 am

You may start it this way:

Code: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Rectangle as bitmap

Postby Antonio Linares » Thu Sep 16, 2021 11:53 am

Enhanced version:

Code: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Rectangle as bitmap

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

Re: Rectangle as bitmap

Postby Antonio Linares » Thu Sep 16, 2021 12:10 pm

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Rectangle as bitmap

Postby nageswaragunupudi » Thu Sep 16, 2021 1:18 pm

Code: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Rectangle as bitmap

Postby Natter » Thu Sep 16, 2021 2:02 pm

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

Re: Rectangle as bitmap

Postby Natter » Tue Sep 21, 2021 6: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 ?
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Postby Antonio Linares » Tue Sep 21, 2021 11:22 am

Yes, it should work the same
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Rectangle as bitmap

Postby Natter » Tue Sep 21, 2021 12:23 pm

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

Re: Rectangle as bitmap

Postby Natter » Thu Oct 07, 2021 9: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
Last edited by Natter on Thu Oct 07, 2021 10:27 am, edited 1 time in total.
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Rectangle as bitmap

Postby Natter » Thu Oct 07, 2021 10:30 am

And how can I get a picture of the entire control surface ?
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Rectangle as bitmap

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Rectangle as bitmap

Postby Natter » Thu Oct 07, 2021 10:44 am

Same result
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 93 guests