FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ximage rotate and save
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
ximage rotate and save
Posted: Tue Jan 09, 2018 09:56 PM
I rotate an image with

@ 230,312 BTNBMP obtnPreview[3] BITMAP "AROTATE" NOBORDER ;
SIZE 18,24 of oAllegati;
ACTION oImagePreview:Rotate()

and the I save it but this function

Code (fw): Select all Collapse
 Function   SalvaImage(oImg)
        Local   nType
       local oBmp  := GdiBmp():New()
       local cFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TIFF (*.tif)| *.tif|" +          ;
                             "PNG   (*.png)| *.png"            ;
                            ,"Salva con il nome",  hb_CurDrive() , .t. )


  * oBmp:hBmp   := GDIP_FROMHBITMAP( oImg:GetHBitmap(), oImg:aPalBmp[ 1 ], .T. )
   oBmp:hBmp   := oImg:aPalBmp[ 1 ]






   IF .NOT. EMPTY( cFile )
             nType := NGETFILEFILTER()


            DO CASE
                  CASE nType == 1
                   cExt := "bmp"
                  CASE nType == 2
                   cExt := "jpg"
                  CASE nType == 3
                   cExt := "gif"
                  CASE nType == 4
                   cExt := "tif"
                  CASE nType == 5
                   cExt := "png"
                ENDCASE

                 cFile := cFilePath( cFile ) + cFileNoExt( cFile ) + "." + cExt

                oBmp:Save(cfile)

                MsgInfo( "saved as: "+ cFile)
   oBmp:End()
  Endif
Return nil



save the image as was before ( on Original)

How I can save the image rotated ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: ximage rotate and save
Posted: Sun Jan 14, 2018 01:26 AM
Try with

Code (fw): Select all Collapse
.../...
SaveImgMod( oImage, "ejemplom.png" )
.../...

//----------------------------------------------------------------------------//

Function SaveImgMod( oImg, cFile, lDimImg )

   local lRet       := .F.
   local oBmp
   local oRect
   DEFAULT lDimImg  := .F.
   if !Empty( cFile )
      oRect      := if( lDimImg, oImg:oRect, oImg:GetCliRect() )
      oBmp       := GdiBmp():New()
      oBmp:hBmp  := GDIPLUSCAPTURERECTWND( oImg:hWnd, ;
                       oRect:nTop  + if( oImg:lBorder, 1, 0 ), ;
                       oRect:nLeft + if( oImg:lBorder, 1, 0 ), ;
                       oRect:nRight - oRect:nLeft - 1 - if( oImg:lBorder, 1, 0 ), ;
                       oRect:nBottom - oRect:nTop - 1 - if( oImg:lBorder, 1, 0 ) )
      lRet  := oBmp:Save( cFile )
      oBmp:End()
   else
      MsgInfo( "Name File Empty", "Attention" )
   endif

Return lRet

//----------------------------------------------------------------------------//
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: ximage rotate and save
Posted: Mon Jan 15, 2018 11:44 AM

How I can Know if the image is modify ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: ximage rotate and save
Posted: Mon Jan 15, 2018 01:15 PM

You have to implement that aspect.

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: ximage rotate and save
Posted: Mon Jan 15, 2018 02:06 PM

if oImage:nZoom == 1 .and. oImage:nRotate == 0
// not modified
else
oImage:SaveToBmp( cBmpFile ) // save rotated / zoomed image to bmp file
endif

Regards



G. N. Rao.

Hyderabad, India
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: ximage rotate and save
Posted: Mon Jan 15, 2018 02:38 PM

Yes, but in this case the image is always recorded with the size of the control, and not with the original size of the image

Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: ximage rotate and save
Posted: Mon Jan 15, 2018 03:08 PM
and it can run good ?
just an idea...


Code (fw): Select all Collapse
//----------------------------------------------------------------------//
Function 聽 SalvaImage(oImg)
聽 聽 聽 聽 Local 聽 nType
聽 聽 聽 聽local oBmp 聽:= GdiBmp():New()
聽 聽 聽 聽local cFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" + 聽 聽 聽 聽 ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽"JPEG 聽(*.jpg)| *.jpg|" + 聽 聽 聽 聽 聽;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽"GIF 聽 (*.gif)| *.gif|" 聽+ 聽 聽 聽 聽 ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽"TIFF (*.tif)| *.tif|" + 聽 聽 聽 聽 聽;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽"PNG 聽 (*.png)| *.png" 聽 聽 聽 聽 聽 聽;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 ,"Salva con il nome", 聽hb_CurDrive() , .t. )


聽 // oBmp:hBmp 聽 := GDIP_FROMHBITMAP( oImg:GetHBitmap(), oImg:aPalBmp[ 1 ], .T. )
聽 聽oBmp:hBmp 聽 := oImg:aPalBmp[ 1 ]

聽 聽IF .NOT. EMPTY( cFile )
聽 聽 聽 聽 聽 聽 聽nType := NGETFILEFILTER()
聽 聽 聽 聽 聽 聽 DO CASE
聽 聽 聽 聽 聽 聽 聽 聽 聽 CASE nType == 1
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽cExt := "bmp"
聽 聽 聽 聽 聽 聽 聽 聽 聽 CASE nType == 2
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽cExt := "jpg"
聽 聽 聽 聽 聽 聽 聽 聽 聽 CASE nType == 3
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽cExt := "gif"
聽 聽 聽 聽 聽 聽 聽 聽 聽 CASE nType == 4
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽cExt := "tif"
聽 聽 聽 聽 聽 聽 聽 聽 聽 CASE nType == 5
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽cExt := "png"
聽 聽 聽 聽 聽 聽 聽 聽 ENDCASE


聽 聽 聽 聽 聽 聽 聽cFile := cFilePath( cFile ) + cFileNoExt( cFile ) + "." + cExt

聽 聽 聽 聽 聽 聽 聽 聽IF oImagePreview:nZoom == 1 .and. oImagePreview:nRotate == 0
聽 聽 聽 聽 聽 聽 聽 聽 聽oImagePreview:SaveImage( cFile )
聽 聽 聽 聽 聽 聽 聽 聽ELSE
聽 聽 聽 聽 聽 聽 聽 聽 聽 SaveImgMod( oImagePreview, 聽cFile,,oBmp )
聽 聽 聽 聽 聽 聽 聽 聽Endif

聽 聽 聽 聽 聽 聽 聽MsgInfo( "saved as: "+ cFile)
聽 聽 聽ENDIF

聽 聽 聽RETURN NIL

//------------------------------------------------------------------//

聽Function SaveImgMod( oImg, cFile, lDimImg ,oBmp)

聽 聽local lRet 聽 聽 聽 := .F.
聽 /聽local oBmp
聽 聽local oRect
聽 聽DEFAULT lDimImg 聽:= .F.
聽 聽if !Empty( cFile )
聽 聽 聽 oRect 聽 聽 聽:= if( lDimImg, oImg:oRect, oImg:GetCliRect() )
聽 聽 //聽 oBmp 聽 聽 聽 := GdiBmp():New()
聽 聽 聽 oBmp:hBmp 聽:= GDIPLUSCAPTURERECTWND( oImg:hWnd, ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oRect:nTop 聽+ if( oImg:lBorder, 1, 0 ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oRect:nLeft + if( oImg:lBorder, 1, 0 ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oRect:nRight - oRect:nLeft - 1 - if( oImg:lBorder, 1, 0 ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oRect:nBottom - oRect:nTop - 1 - if( oImg:lBorder, 1, 0 ) )
聽 聽 聽 lRet 聽:= oBmp:Save( cFile )
聽 聽 聽 oBmp:End()
聽 聽else
聽 聽 聽 MsgInfo( "Name File Empty", "Attention" )
聽 聽endif

Return lRet
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: ximage rotate and save
Posted: Mon Jan 15, 2018 03:28 PM
cnavarro wrote:Yes, but in this case the image is always recorded with the size of the control, and not with the original size of the image
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: ximage rotate and save
Posted: Tue Jan 16, 2018 09:13 AM
It save right the picture is rotated but when it save is saved all dialog and not only the image

see here



see also the scroll is saved
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: ximage rotate and save
Posted: Tue Jan 16, 2018 10:29 AM
Silvio , you can use tgdiplus :-)



Code (fw): Select all Collapse
Function saveimage( cSaveName, 聽Hbitmap , nzoom, nrotate )
local oBmp:= GDIBmp():New( )
oBmp:hbmp := GdiPlusCreateImageFromhBitmap( Hbitmap )
obmp:rotate( nrotate )
obmp:resize( 聽 聽obmp:GetWidth() * nzoom , obmp:GetHeight()*nzoom )
obmp:save ( cSaveName ) 
obmp:end()

Return nil


Saludos.
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: ximage rotate and save
Posted: Tue Jan 16, 2018 11:04 AM
Manuel not run

Code (fw): Select all Collapse
Function SalvaImage(oImg)
   Local nType
  // local oBmp  := GdiBmp():New()
      local cFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                                "JPEG  (*.jpg)| *.jpg|" +          ;
                                "GIF   (*.gif)| *.gif|"  +         ;
                                "TIFF (*.tif)| *.tif|" +           ;
                                "PNG   (*.png)| *.png"            ;
                                ,"Salva con il nome",  hb_CurDrive() , .t. )


  // oBmp:hBmp   := GDIP_FROMHBITMAP( oImg:GetHBitmap(), oImg:aPalBmp[ 1 ], .T. )
  //oBmp:hBmp   := oImg:aPalBmp[ 1 ]

   IF .NOT. EMPTY( cFile )
             nType := NGETFILEFILTER()

            DO CASE
                  CASE nType == 1
                   cExt := "bmp"
                  CASE nType == 2
                   cExt := "jpg"
                  CASE nType == 3
                   cExt := "gif"
                  CASE nType == 4
                   cExt := "tif"
                  CASE nType == 5
                   cExt := "png"
                ENDCASE


             cFile := cFilePath( cFile ) + cFileNoExt( cFile ) + "." + cExt

           
                  saveimage( cFile,  oImg:GetHBitmap() , oImg:nzoom, oImg:nrotate )
            

             MsgInfo( "saved as: "+ cFile)
     ENDIF

     RETURN NIL

     Function saveimage( cSaveName,  Hbitmap , nzoom, nrotate )
local oBmp:= GDIBmp():New( )
oBmp:hbmp := GdiPlusCreateImageFromhBitmap( Hbitmap )
obmp:rotate( nrotate )
obmp:resize(    obmp:GetWidth() * nzoom , obmp:GetHeight()*nzoom )
obmp:save ( cSaveName )
obmp:end()

Return nil
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: ximage rotate and save
Posted: Tue Jan 16, 2018 02:23 PM

see also the scroll is saved


Try with last parameter in function SaveImgMod( oImg, cFile, lDimImg ) // .T. or .F.
I think function Manuel is very good function, but save method return .F., thanks
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: ximage rotate and save
Posted: Tue Jan 16, 2018 09:44 PM
silvio , look ...
Code (fw): Select all Collapse
Function SalvaImage(oImg)
   Local nType
   local cFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                                "JPEG  (*.jpg)| *.jpg|" +          ;
                                "GIF   (*.gif)| *.gif|"  +         ;
                                "TIFF (*.tif)| *.tif|" +           ;
                                "PNG   (*.png)| *.png"            ;
                                ,"Salva con il nome",  hb_CurDrive() , .t. )


    IF .NOT. EMPTY( cFile )
             nType := NGETFILEFILTER()

            DO CASE
                  CASE nType == 1
                   cExt := "bmp"
                  CASE nType == 2
                   cExt := "jpg"
                  CASE nType == 3
                   cExt := "gif"
                  CASE nType == 4
                   cExt := "tif"
                  CASE nType == 5
                   cExt := "png"
                ENDCASE


             cFile := cFilePath( cFile ) + cFileNoExt( cFile ) + "." + cExt

             saveimage( oimage, cFile )
            

             MsgInfo( "saved as: "+ cFile)
     ENDIF

     RETURN NIL


Function saveimage( oImage, cSaveName ) 

local oBmp:= GDIBmp():New( )
local hbitmap:= oimage:GetHBitmap()

obmp:hbmp := GDIP_FROMHBITMAP( hbitmap  )

if oImage:nRotate != 0
   obmp:hbmp:= GdiPlusImageRotateAngle( obmp:hBmp, oImage:nRotate , .f. )
endif

 if oimage:nZoom != 1
   obmp:resize( obmp:Getwidth() * oimage:nZoom, obmp:GetHeight() * oimage:nZoom  ) 
endif

obmp:save( cSaveName )
 DeleteObject( hbitmap )
 
obmp:end()  

Return nil
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: ximage rotate and save
Posted: Tue Jan 16, 2018 09:57 PM
thanks Manuel
:-) :-) :-) :-)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion