BT_BitmapSaveFile

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: BT_BitmapSaveFile

Post by gfilatov »

serge_girard wrote:Hello,


When I 'drop' a drawing on the picture it seems OK but when the window/form is minimized and opened again my draw has disappeared Almost like an UNDO...

Any idea how to make it mot disappear?
Hello Serge,

You should to add your drawing to HMG internal array for painting after minimizing of the window.

Example:

Code: Select all

FUNCTION Draw_Figure()
/*********************/
   LOCAL i := GetFormIndex ( 'Win1' )
STATIC struct := {NIL,NIL,NIL,NIL,NIL,NIL}

...

IF   lCopy1 .OR. lCopy2 .OR. lCopy3 
   IF nMouse_Row >= 10 .and. nMouse_Row <= 480  .AND. nMouse_Col >= 100  .AND. nMouse_Col <= 840   // op de foto
      IF   lCopy1
         BT_DrawEllipse (hDC, nMouse_Row-15, nMouse_Col-15, 30, 30, RED, 1)
         struct[1] := nMouse_Row-15
         struct[2] := nMouse_Col-15
         AAdd( _HMG_SYSDATA [ 102 ] [i] , { || BT_DrawEllipse (hDC, struct[1], struct[2], 30, 30, RED, 1) } )
         SetProperty('Win1','Label_1', 'Value', ALLTRIM(STR(nMouse_Row)) + ' ' +    ALLTRIM(STR(nMouse_Col)) )
         lCopy1      := .F.
      ENDIF

      IF   lCopy2
         BT_DrawEllipse (hDC, nMouse_Row-15, nMouse_Col-15, 30, 30, GREEN, 1)
         struct[3] := nMouse_Row-15
         struct[4] := nMouse_Col-15
         AAdd( _HMG_SYSDATA [ 102 ] [i] , { || BT_DrawEllipse (hDC, struct[3], struct[4], 30, 30, GREEN, 1) } )
         SetProperty('Win1','Label_2', 'Value', ALLTRIM(STR(nMouse_Row)) + ' ' +    ALLTRIM(STR(nMouse_Col)) )
         lCopy2      := .F.
      ENDIF

      IF   lCopy3
         BT_DrawEllipse (hDC, nMouse_Row-30, nMouse_Col-30, 60, 60, ORANGE, 1)
         struct[5] := nMouse_Row-30
         struct[6] := nMouse_Col-30
         AAdd( _HMG_SYSDATA [ 102 ] [i] , { || BT_DrawEllipse (hDC, struct[5], struct[6], 60, 60, ORANGE, 1) } )
         SetProperty('Win1','Label_3', 'Value', ALLTRIM(STR(nMouse_Row)) + ' ' +    ALLTRIM(STR(nMouse_Col)) )
         lCopy3      := .F.
      ENDIF

   ENDIF
...
Hope that give you an idea :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: BT_BitmapSaveFile

Post by serge_girard »

Great ! I knew one had to save the changes, but I didn't know how to do it.

Thank you Grigory !
There's nothing you can do that can't be done...
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: BT_BitmapSaveFile

Post by andyglezl »

Yo tambien tenia esa duda y esa idea de que habia que guardar "algo", voy a probar.
viewtopic.php?f=6&t=3271&p=29778#p29778

Pregunta: Si yo borro el comando que añadí, estoy haciendo un "UNDO" ?

AAdd( _HMG_SYSDATA [ 102 ] , { || BT_DrawEllipse (hDC, struct[1], struct[2], 30, 30, RED, 1) } )
---------------------------------------------------------------------------------------------------


I also had this doubt and the idea that he had to keep "something", I'll try.
viewtopic.php?f=6&t=3271&p=29778#p29778

Question: If I delete the command that I added, I'm doing a "UNDO"?

AAdd( _HMG_SYSDATA [ 102 ] , { || BT_DrawEllipse (hDC, struct[1], struct[2], 30, 30, RED, 1) } )
---------------------------------------------------------------------------------------------------
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: BT_BitmapSaveFile

Post by serge_girard »

Andrés,

I think deleting the right entry would indeed do an UNDO. I will try later on.

Greetings, Serge
There's nothing you can do that can't be done...
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: BT_BitmapSaveFile

Post by andyglezl »

Bueno, ya se ve avance.
Ahora al minimizar y maximizar, si deja el dibujo,
pero solo el último que se hizo. seguimos probando...
------------------------------------------------------

Well, it looks forward.
Now when minimizing and maximizing, repaint the drawing,
but only the last one did. still trying ...
Attachments
imagen.jpg
imagen.jpg (61.28 KiB) Viewed 2880 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: BT_BitmapSaveFile

Post by srvet_claudio »

Andres, proba con esto:

Code: Select all


#include "hmg.ch"
#include "hfcl.ch"


FUNCTION MAIN
PRIVATE cFileName := "BosTaurus_logo.JPG"

   DEFINE WINDOW Win1;
      AT 0,0 ;
      WIDTH 600 ;
      HEIGHT 650 ;
      MAIN;
      TITLE "Click on the picture";
      ON INIT    Proc_ON_INIT ();
      ON RELEASE Proc_ON_RELEASE()
      
      @ 5, 50 IMAGE Image1 PICTURE "" ACTION Proc_ON_CLICK()

   END WINDOW
   CENTER WINDOW Win1
   ACTIVATE WINDOW Win1
RETURN NIL


PROCEDURE Proc_ON_INIT
LOCAL hBitmap := 0
  hBitmap := BT_BitmapLoadFile (cFileName)
  BT_HMGSetImage ("Win1", "Image1", hBitmap)
RETURN


PROCEDURE Proc_ON_CLICK
LOCAL hDC, BTstruct
LOCAL hBitmap
LOCAL nRow :=  Random (300)
LOCAL nCol :=  Random (300)

   hBitmap := BT_HMGGetImage ("Win1", "Image1")

   hDC := BT_CreateDC (hBitmap, BT_HDC_BITMAP, @BTstruct)
       BT_DrawEllipse (hDC, nRow, nCol, 40, 40, RED, 3)   // Draw in image
   //  BT_Draw... ()                                      // Others draw functions
   BT_DeleteDC (BTstruct)
   
   BT_ClientAreaInvalidateAll ("Win1")
RETURN


PROCEDURE Proc_ON_RELEASE
LOCAL hBitmap
   hBitmap := BT_HMGGetImage ("Win1", "Image1")
   BT_BitmapSaveFile (hBitmap, "Image_33.png", BT_FILEFORMAT_PNG)
   BT_BitmapRelease (hBitmap)
RETURN

Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: BT_BitmapSaveFile

Post by andyglezl »

Hola Dr. Claudio, acabo de instalar HMG3.1.5 y probe su ejemplo, funciona correcto, ya no se borra lo dibujado al minimizar
o sobreponer alguna otra ventana.

Lo que si note, es que cada vez que se da un click, hace un parpadeo muy visible. (me supongo que es al repintar la imagen)

Empezare a hacer algunas pruebas con esta version con los programas que ya tengo hechos.

Gracias!!!
-------------------------------------------------------------------

Hello Dr. Claudio, I just installed HMG3.1.5 and probe their example, works correct, because it is not deleted drawn to minimize
or some other window overlaying.

What I did notice is that every time there is a click, a blink ago very visible. (I guess it is to repaint the image)

I'll start doing some testing with this version with the programs
I have already made​​.

Thank you!
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: BT_BitmapSaveFile

Post by andyglezl »

Perdon, gracias tambien a gfilatov por el ejemplo anterior.

-------------------------------------------------------

Sorry, thanks also to gfilatov by the previous example.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: BT_BitmapSaveFile

Post by andyglezl »

Grandioso Dr. Soto. es usted un genio !!!, Hice algunos cambios al ejemplo que envió.
-----------------------------------------------------------------------------------
Great Dr. Soto. you are a genius !!!, I made some changes to the example you sent.
-----------------------------------------------------------------------------------

Code: Select all

#include "hmg.ch"
#include "hfcl.ch"


FUNCTION MAIN
	PRIVATE cFileName := "MapaEdos.Rep.Mex.jpg"		//   <== Put your image
	PRIVATE hBitmap:=0, ImgWidth:=0 , ImgHeight:=0

	DEFINE WINDOW Win1;
		AT 0,0 ;
		WIDTH 600 ;
		HEIGHT 650 ;
		MAIN;
		TITLE "Click on the picture"   ;
		ON INIT    Proc_ON_INIT ()     ;
		ON RELEASE Proc_ON_RELEASE()
     
		@ 0,0 IMAGE Image1 PICTURE "" ACTION Proc_ON_CLICK()
		
		DEFINE CONTEXT MENU OF Win1

			MENUITEM "Reload"   ACTION { ||  hBitmap := BT_BitmapLoadFile( cFileName ),   ;
													BT_HMGSetImage( "Win1", "Image1", hBitmap ), ;
													BT_ClientAreaInvalidateAll( "Win1" ) }
			SEPARATOR
			MENUITEM "Invert"   ACTION { || BT_BitmapInvert( hBitmap ), BT_ClientAreaInvalidateAll( "Win1" ) }
			MENUITEM "Gray"     ACTION { || BT_BitmapGrayness( hBitmap, 100 ), BT_ClientAreaInvalidateAll( "Win1" ) }
			MENUITEM "Horizontal reflect" ACTION { ||  hBitmap:=BT_BitmapTransform( hBitmap, BT_BITMAP_REFLECT_HORIZONTAL, 90, BLACK ), ;
																BT_HMGSetImage( "Win1", "Image1", hBitmap ), ;
																BT_ClientAreaInvalidateAll( "Win1" ) }
			MENUITEM "Vertical reflect"   ACTION { ||  hBitmap:=BT_BitmapTransform( hBitmap, BT_BITMAP_REFLECT_VERTICAL, 90, BLACK ), ;
																BT_HMGSetImage( "Win1", "Image1", hBitmap ), ;
																BT_ClientAreaInvalidateAll( "Win1" ) }
			SEPARATOR
			MENUITEM "Save"  ACTION { || SaveImg( ) }			
		END MENU

	END WINDOW
	CENTER WINDOW Win1
	ACTIVATE WINDOW Win1
RETURN NIL


PROCEDURE Proc_ON_INIT
	hBitmap     := BT_BitmapLoadFile( cFileName )
	Win1.Width  := ImgWidth    := BT_BitmapWidth( hBitmap )
	Win1.Height := ImgHeight   := BT_BitmapHeight( hBitmap )
	Win1.Center
	BT_HMGSetImage("Win1", "Image1", hBitmap)
RETURN

PROCEDURE Proc_ON_CLICK
	LOCAL hDC, BTstruct
	LOCAL hBitmap
	LOCAL nRow := Random( ImgHeight )
	LOCAL nCol := Random( ImgWidth )

	hBitmap := BT_HMGGetImage( "Win1", "Image1" )

	hDC := BT_CreateDC( hBitmap, BT_HDC_BITMAP, @BTstruct )
	BT_DrawEllipse( hDC, nRow, nCol, 40, 40, RED, 3 )   // Draw in image
	//  BT_Draw... ()                                   // Others draw functions
	BT_DeleteDC(BTstruct)
	BT_ClientAreaInvalidateAll("Win1")								// Repinta toda el area
RETURN

PROCEDURE SaveImg
	LOCAL hBitmap
	hBitmap := BT_HMGGetImage( "Win1", "Image1" )
	BT_BitmapSaveFile( hBitmap, "Image_33.png", BT_FILEFORMAT_PNG )
	MsgInfo( "Saved Image..." )
RETURN
PROCEDURE Proc_ON_RELEASE
	BT_BitmapRelease( hBitmap )
RETURN
Faltaría como poder deshacer cada dibujo individualmente ?,
esperemos que sigan mejorando y publicando los avances de este ejemplo.
-------------------------------------------------------------------------
How to undo each picture individually?,
we hope to continue improving and publishing progress of this example.
Attachments
BosTaurusEjem.jpg
BosTaurusEjem.jpg (63.88 KiB) Viewed 2812 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: BT_BitmapSaveFile

Post by andyglezl »

Hola Dr. Soto

De esta ultima forma, utilizando un control IMAGE (en vez de cargar la imagen en el evento ON PAINT)
no me me asigna los valores de la posicion del cursor. ( nRow:=_HMG_SYSDATA [ 191 ] y nCol:=_HMG_SYSDATA [ 192 ] )

Por lo que he visto, solamente cuando la ventana no tiene controles que "interfieran", si asigna los valores, en este caso
el control IMAGE como abarca toda la ventana no permite asignar los valores.

Alguien conoce alguna otra forma de obtener esos valores ?
------------------------------------------------------------------------------
Hello Dr. Soto

In this last form, using IMAGE control (instead of loading the image in the event ON PAINT)
do not assign me the values ​​of cursor position. (NRow: = _HMG_SYSDATA [191] and nCol: = _HMG_SYSDATA [192])

From what I've seen, only when the window has no controls to "interfere" if assigned values​​,
in this case IMAGE control covers the entire window as not to assign the values.

Anyone know of any other way to get those values?
------------------------------------------------------------------------------

Code: Select all

        .............
	DEFINE WINDOW Win1 AT 0,0 WIDTH 600 HEIGHT 650 MAIN  ;
		TITLE ""  ;
		ON INIT    Proc_ON_INIT ()     	;
		ON MOUSEMOVE UpdYX() 			;
		ON RELEASE Proc_ON_RELEASE()
        .............
        .............

FUNCTION UpdYX()
	nRow:=_HMG_SYSDATA [ 191 ]
	nCol:=_HMG_SYSDATA [ 192 ]
	Win1.Title:= "DEMO -   Click on Window to Draw...       "+PADC( nRow,5)+" / "+PADC( nCol,5)
RETURN
PROCEDURE Proc_ON_CLICK
	LOCAL BTstruct  //  hDC, 
	LOCAL hBitmap
	nRow:=_HMG_SYSDATA [ 191 ]
	nCol:=_HMG_SYSDATA [ 192 ]
	*LOCAL nRow := Random( ImgHeight )
	*LOCAL nCol := Random( ImgWidth )
        .............
        .............
        .............
RETURN
Andrés González López
Desde Guadalajara, Jalisco. México.
Post Reply