ximage rotate and save

Post Reply
User avatar
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

ximage rotate and save

Post 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

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
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: ximage rotate and save

Post by cnavarro »

Try with

Code: Select all | Expand



.../...
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
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: ximage rotate and save

Post by Silvio.Falconi »

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
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: ximage rotate and save

Post by cnavarro »

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
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: ximage rotate and save

Post by nageswaragunupudi »

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
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: ximage rotate and save

Post 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
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
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: ximage rotate and save

Post by Silvio.Falconi »

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


Code: Select all | Expand




//----------------------------------------------------------------------//
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
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: ximage rotate and save

Post 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
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
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: ximage rotate and save

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

Re: ximage rotate and save

Post by mastintin »

Silvio , you can use tgdiplus :-)



Code: Select all | Expand



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
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: ximage rotate and save

Post by Silvio.Falconi »

Manuel not run

Code: Select all | Expand

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
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: ximage rotate and save

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

Re: ximage rotate and save

Post by mastintin »

silvio , look ...

Code: Select all | Expand



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
Silvio.Falconi
Posts: 7136
Joined: Thu Oct 18, 2012 7:17 pm
Been thanked: 1 time

Re: ximage rotate and save

Post by Silvio.Falconi »

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
Post Reply