Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why the picture after rotating can not saved correctly

Status
Not open for further replies.

Subiyantoro

Programmer
Oct 28, 2015
2
AU
Sorry, I don't speak English very well.

Code:
Public oform1

oform1=Newobject("form1")
oform1.Show
Return
Define Class form1 As Form
    Top = 2
    Left = 70
    Height = 481
    Width = 603
    DoCreate = .T.
    Caption = "Form1"
    nsavegraphicshandle = .t.
    Name = "Form1"
     
    Add Object command1 As CommandButton With ;
        Top = 396, ;
        Left = 288, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Get Image", ;
        Name = "Command1"
    Procedure command1.Click
        lcPic = Getpict()
        lnAngle = 45
        Public oGr As GpGraphics Of Home(1)+"Ffc\_gdiplus.vcx"
        oGr = Newobject('GpGraphics',Home(1)+'Ffc\_gdiplus.vcx')
        oGr.CreateFromHWND(Thisform.HWnd)
        Public oLogoImage As GpImage Of Home(1)+"ffc\_gdiplus.vcx"
        oLogoImage = Newobject('GpImage',Home(1)+'ffc\_gdiplus.vcx')
        oLogoImage.CreateFromFile(lcPic)   

		 oRect= Newobject( ;
            'GpRectangle',Home(1)+'ffc\_gdiplus.vcx','',5, 5,;
             ologoimage.ImageWidth , ologoimage.ImageHeight )
        If  lnAngle > 0
            lnX = 100
            lnY = 100
            oGr.TranslateTransform(lnX, lnY, 0)
            oGr.RotateTransform(lnAngle, 0)
            oGr.TranslateTransform(-lnX, -lnY, 0)
        Endif
        oGr.DrawImageScaled( oLogoImage, oRect )
        ologoimage.SaveToFile('c:\ImgRot.jpg',"image/jpeg",'quality=100')
    Endproc
Enddefine
 
oGr.DrawImageScaled( oLogoImage, oRect ) does not transform ologoimage, ologoimage is unchanged. OGr acts on what you assign to it via oGr.CreateFrom..., in your case it acts on the form, as you create it from hwnd.

What you need is an empty GpImage and oGr.CreateFromImage(oEmptyImage), then apply the transformations and finally oEmptyImage.SaveToFile('rotated.jpg','image/jpeg','quality=100')

Besides that, you better use GdiplusX from the VFPX project, for usage and sample trasnformations see
Bye, Olaf.
 
Dear Olaf,

I changed my script as you guide into

Code:
Public oform1

oform1=Newobject("form1")
oform1.Show
Return
Define Class form1 As Form
    Top = 2
    Left = 70
    Height = 481
    Width = 603
    DoCreate = .T.
    Caption = "Form1"
    nsavegraphicshandle = .t.
    Name = "Form1"
     
    Add Object command1 As CommandButton With ;
        Top = 396, ;
        Left = 288, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Get Image", ;
        Name = "Command1"
    Procedure command1.Click
        lcPic = Getpict()
        lnAngle = 45
        Public oGr As GpGraphics Of Home(1)+"Ffc\_gdiplus.vcx"
        oGr = Newobject('GpGraphics',Home(1)+'Ffc\_gdiplus.vcx')
*!*	        oGr.CreateFromHWND(Thisform.HWnd)
        Public oLogoImage As GpImage Of Home(1)+"ffc\_gdiplus.vcx"
        oLogoImage = Newobject('GpImage',Home(1)+'ffc\_gdiplus.vcx')
        oLogoImage.CreateFromFile(lcPic)
        
        
      
        oGr.CreateFromimage(ologoimage)  

		 oRect= Newobject( ;
            'GpRectangle',Home(1)+'ffc\_gdiplus.vcx','',5, 5,;
             ologoimage.ImageWidth , ologoimage.ImageHeight )
        If  lnAngle > 0
            lnX = 100
            lnY = 100
            oGr.TranslateTransform(lnX, lnY, 0)
            oGr.RotateTransform(lnAngle, 0)
            oGr.TranslateTransform(-lnX, -lnY, 0)
        Endif
        oGr.DrawImageScaled( oLogoImage, oRect )
        ologoimage.SaveToFile('c:\ImgRot.jpg',"image/jpeg",'quality=100')
    Endproc
Enddefine

But the results have not changed
 
What's the problem? No image saved? Don't save to C:\ root, that's most probably forbidden, save into a folder. C:\images\imgrot.jpg.

It works , but it adds the rotated image on the original image. I said you need an empty image, a blank image.

Bye, Olaf.
 
It works for me too as Olaf describes. Just wondering how to create an empty image file?

Stanley
 
Olaf,

Would using vfp's low level file commands to create a 0 length file named with an image file extension (jpg, png, bmp) work just as well? That would be easier than ole'ing up a MS paint app to create it.
Thanks,
Stanley
 
Well,

1. It would be more ideal to create the empty image in memory, but using VFPs gdi+ classes the gpImage class only offers CreateFromFile or from a handle. You don't have all the possibilities of the VFPX GDIPlusX project.
2. A 0 byte file with any image extension is not taken as a blank image, you need a minimum header for image dimensions.
3. The situation still is not that bad. You only need to create an empty image once, it's not changed, like the unrotated image it's just a source, you finally call .SaveToFile with a new file name, so the blank image is not something you consume and need to create every time.

But
4. Since the blank image color you could need differs from time to time, using the VFPX GDIPlusX project would make more sense.

So finally, please use VFPX.

Code:
Do system.app
With _screen.system.drawing
   local loblankbmp as xfcbitmap
   loblankbmp = .bitmap.new(width,height)

   local logfx as xfcgraphics
   logfx = .graphics.fromimage(loblankbmp)
   logfx.clear(.color.fromrgb(r,g,b))
   ...
Endwith

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top