Page 1 of 1

ximage rotate and save

PostPosted: Tue Jan 09, 2018 9:56 pm
by Silvio.Falconi
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 ?

Re: ximage rotate and save

PostPosted: Sun Jan 14, 2018 1:26 am
by cnavarro
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

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

Re: ximage rotate and save

PostPosted: Mon Jan 15, 2018 11:44 am
by Silvio.Falconi
How I can Know if the image is modify ?

Re: ximage rotate and save

PostPosted: Mon Jan 15, 2018 1:15 pm
by cnavarro
You have to implement that aspect.

Re: ximage rotate and save

PostPosted: Mon Jan 15, 2018 2:06 pm
by nageswaragunupudi
if oImage:nZoom == 1 .and. oImage:nRotate == 0
// not modified
else
oImage:SaveToBmp( cBmpFile ) // save rotated / zoomed image to bmp file
endif

Re: ximage rotate and save

PostPosted: Mon Jan 15, 2018 2:38 pm
by cnavarro
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

Re: ximage rotate and save

PostPosted: Mon Jan 15, 2018 3:08 pm
by Silvio.Falconi
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






 

Re: ximage rotate and save

PostPosted: Mon Jan 15, 2018 3:28 pm
by cnavarro
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

Re: ximage rotate and save

PostPosted: Tue Jan 16, 2018 9:13 am
by Silvio.Falconi
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

Re: ximage rotate and save

PostPosted: Tue Jan 16, 2018 10:29 am
by mastintin
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.

Re: ximage rotate and save

PostPosted: Tue Jan 16, 2018 11:04 am
by Silvio.Falconi
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

Re: ximage rotate and save

PostPosted: Tue Jan 16, 2018 2:23 pm
by cnavarro
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

Re: ximage rotate and save

PostPosted: Tue Jan 16, 2018 9:44 pm
by mastintin
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

 

Re: ximage rotate and save

PostPosted: Tue Jan 16, 2018 9:57 pm
by Silvio.Falconi
thanks Manuel
:D :D :D :D