Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



SCALE AND SHEAR WITH GDI+

Execute the code below to change Shear and Scale of an image.

Special Thanks to Anatolyi Mogylevets, from www.news2news.com
A great part of this code comes from him, once _gdiplus.vcx is still incomplete, what obliges us to call directly through API http://www.news2news.com/vfp/?example=479

To Better understand how Scale and Shear work with GDI+, take a look at these links too :
http://www.vbaccelerator.com/home/VB/Code/vbMedia/Using_GDI_Plus/Scale__Rotate__Skew_and_Transform_Images/article.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlusreference/classes/matrixclass/matrixmethods/shear.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlusreference/classes/matrixclass/matrixmethods/shear.asp

 

* SCALE AND SHEAR WITH GDI+
* --------------------------
* Special Thanks to Anatolyi Mogylevets, from
www.news2news.com
* A great part of this code comes from him, once _gdiplus.vcx
* is still incomplete what obliges us to call directly through API
http://www.news2news.com/vfp/?example=479

DECLARE INTEGER GdipCreateMatrix IN gdiplus INTEGER @matrix
DECLARE INTEGER GdipDeleteMatrix IN gdiplus INTEGER matrix
DECLARE INTEGER GdipShearMatrix IN gdiplus;
        INTEGER matrix, SINGLE shearX, SINGLE shearY, INTEGER ord
DECLARE INTEGER GdipScaleMatrix IN gdiplus; 
        INTEGER matrix, SINGLE scaleX, SINGLE scaleY, INTEGER ord
DECLARE INTEGER GdipSetWorldTransform IN gdiplus; 
        INTEGER graphics, INTEGER matrix

lcSource = GETPICT("jpg;gif;bmp")
lcDestination = ADDBS(JUSTPATH(lcSource))+ "Sheared_" +;
   JUSTSTEM(lcSource)+".jpg"
LOCAL loImage AS GpImage OF _gdiplus.vcx
loImage = NEWOBJECT("GpImage", HOME() + "FFC/_gdiplus.vcx")
loImage.CreateFromFile(lcSource)
 
LOCAL loBitmap AS GpBitmap OF _gdiplus.vcx
loBitmap = NEWOBJECT("GpBitmap", HOME() + "FFC/_gdiplus.vcx")
LOCAL loGraphics AS GpGraphics OF _gdiplus.vcx
loGraphics = NEWOBJECT('GpGraphics',HOME() + "FFC/_gdiplus.vcx")

*** Now we create a new image with
*** Create Method - Creates a bitmap object.
*** Syntax: ? THIS.Create(tnWidth, tnHeight[, tnPixelFormat])
*** tnPixelFormat, optional, one of GDIPLUS_PIXELFORMAT_* constants,
*** defaults to GDIPLUS_PIXELFORMAT_32bppARGB.
 
LOCAL lnWidth, lnHeight, lnPixelFormat
lnWidth = loImage.ImageWidth
lnHeight = loImage.ImageWidth
lnPixelFormat = loImage.PixelFormat

LOCAL matrix1, xScaleFactor, yScaleFactor, xShearfactor, yShearFactor
xScaleFactor = 1.30
yScaleFactor = 0.75

xShearFactor = 0.20
yShearFactor = 0.10

STORE 0 TO matrix1 
 
lnNewWidth  = lnWidth  * xScaleFactor * (1 + xShearFactor)
lnNewHeight = lnHeight * yScaleFactor * (1 + yShearFactor)

loBitmap.Create(lnNewWidth, lnNewHeight, lnPixelFormat)
loGraphics.CreateFromImage(loBitmap)

* create Matrix object
* and apply scale and shear transformations
= GdipCreateMatrix(@matrix1)
= GdipScaleMatrix(matrix1, xScaleFactor, yScaleFactor, 0)
= GdipShearMatrix(matrix1, xShearFactor, yShearFactor, 0)
= GdipSetWorldTransform(loGraphics.GetHandle(), matrix1)
loGraphics.DrawImageAt(loImage, 0, 0)
loGraphics.ResetTransform()
= GdipDeleteMatrix(matrix1)

loBitmap.SaveToFile(lcDestination, "image/jpeg")

Published Thursday, February 09, 2006 4:49 PM by cesarchalom
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Vassilis said:

Wow! I tried to do the same using GdipDrawImagePoints but with no luck.
Your implementation works very nicely.

Thank you!
Vassilis
February 10, 2006 11:02 AM
 

Cesar said:

Glad to know it helped you !
Cesar
February 10, 2006 11:59 AM
 

foxpro.catalyst ?? » Blog Archive » More VFP9 and GDIs said:

October 8, 2007 10:10 PM

What do you think?

(required) 
(optional)
(required)