Rotate

The Rotate method performs a rotation of the image data, copying the image from an active imagespace into an inactive imagespace.

Rotate vAngle, bCalculateOnly, vWidth, vHeight [,vOffsetX] [,vOffsetY]

Parameters

vAngle
Specifies the angle of rotation, in degrees, counter-clockwise.

bCalculateOnly
If True, the method only calculates width and height of imagespace required to fully contain the rotated image (without actually rotating the image). If False, the method rotates the image (calculation is also performed).

vWidth
On input, the vWidth variable should contain the width of the source image. On output, variable contains the width necessary to fully contain the rotated image.

vHeight
On input, the vHeight variable contains height of the source image. On output, variable contains the height necessary to fully contain the rotated image.

vOffsetX
Optional. Specifies a horizontal offset for the rotated image. Default value is 0.

vOffsetY
Optional. Specifies a vertical offset for rotated image. Default value is 0.

Remarks

The "active image" means the image currently selected by calling SelectClipboard.
If the target imagespace is not large enough to fully contain the rotated image then the image will be clipped.

Example 1
The following example rotates an image 10 degrees counter-clockwise

View result


Set g = CreateObject("shotgraph.image")
filename = "c:\i\harbor.jpg"

angle = 10

g.GetFileDimensions filename,width,height
newwidth = width
newheight = height
' Calculate requred dimensions for new image
g.Rotate angle,True,newwidth,newheight
' Create primary imagespace
g.CreateImage newwidth,newheight,256
g.InitClipboard width,height
g.SelectClipboard True
g.ReadImage filename,palette,0,0
' Rotate image in the secondary imagespace
' and write it into in the primary one
' a1 and a2 are dumb parameters here.
g.Rotate angle,False,a1,a2
g.SelectClipboard False
g.JpegImage 90,0,"c:\i\rotated.jpg"
Wscript.echo "Ok"



Example 2
The following example resizes an image if it is larger than the specified size and rotates it.

View result


Const maxwidth = 150
Const maxheight = 150

Set g = CreateObject("shotgraph.image")

file = "c:\i\harbor.jpg"
newfile = "c:\i\i1578.rotated.jpg"

RotateFile file,10,newfile

Wscript.echo "Ok"

''''''''''''''''''''''
''  END
''''''''''''''''''''''



Sub RotateFile(filename,angle,newfilename)
Dim width,height,newwidth,newheight,rwidth,rheight
Dim a1,a2
Dim palette

g.GetFileDimensions filename,width,height
if width = 0 then Exit Sub

if width > maxwidth or height > maxheight then
	' Image needs to be resized
	if width/maxwidth > height / maxheight then
		rwidth = maxwidth
		rheight = height * maxwidth / width
	else
		rheight = maxheight
		rwidth = width * maxheight / height
	end if
	' Read source image into primary imagespace
	g.CreateImage width,height,256
	g.ReadImage filename,palette,0,0
	g.InitClipboard rwidth,rheight
	' Resize image in primary imagespace to secondary imagespace
	g.Stretch 0,0,rwidth,rheight,0,0,width,height,"SRCCOPY","HALFTONE"
	width = rwidth
	height = rheight
else
	' Dumb primary imagespace
	g.CreateImage 1,1,256
	g.InitClipboard width,height
	g.SelectClipboard True
	' Read source image into secondary imagespace
	g.ReadImage filename,palette,0,0
end if

' Now, the rotated image is located in the secondary imagespace
newwidth = width
newheight = height
' Calculate required image size (alter newwidth, newheight variables)
g.Rotate angle,True,newwidth,newheight
g.CreateImage newwidth,newheight,256
g.SelectClipboard True
' Read source image into secondary imagespace
g.Rotate angle,False,a1,a2
g.SelectClipboard False

g.JpegImage 90,0,newfilename

End Sub