ximage rotate and save

ximage rotate and save

Postby Silvio.Falconi » Tue Jan 09, 2018 9: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: Select all  Expand view
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: ximage rotate and save

Postby cnavarro » Sun Jan 14, 2018 1:26 am

Try with

Code: Select all  Expand view


.../...
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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: ximage rotate and save

Postby Silvio.Falconi » 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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: ximage rotate and save

Postby cnavarro » Mon Jan 15, 2018 1: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: ximage rotate and save

Postby nageswaragunupudi » Mon Jan 15, 2018 2: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
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ximage rotate and save

Postby cnavarro » Mon Jan 15, 2018 2: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: ximage rotate and save

Postby Silvio.Falconi » Mon Jan 15, 2018 3:08 pm

and it can run good ?
just an idea...


Code: Select all  Expand view



//----------------------------------------------------------------------//
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: ximage rotate and save

Postby cnavarro » Mon Jan 15, 2018 3: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: ximage rotate and save

Postby Silvio.Falconi » Tue Jan 16, 2018 9:13 am

It save right the picture is rotated but when it save is saved all dialog and not only the image

see here

Image

see also the scroll is saved
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: ximage rotate and save

Postby mastintin » Tue Jan 16, 2018 10:29 am

Silvio , you can use tgdiplus :-)



Code: Select all  Expand view


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.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: ximage rotate and save

Postby Silvio.Falconi » Tue Jan 16, 2018 11:04 am

Manuel not run

Code: Select all  Expand view
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: ximage rotate and save

Postby cnavarro » Tue Jan 16, 2018 2: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
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: ximage rotate and save

Postby mastintin » Tue Jan 16, 2018 9:44 pm

silvio , look ...
Code: Select all  Expand view


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

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: ximage rotate and save

Postby Silvio.Falconi » Tue Jan 16, 2018 9:57 pm

thanks Manuel
:D :D :D :D
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

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