This procedure will rotate 90 deg. in either direction no API required.
It's the same as the link provided by davido but you don't have to search through a huge program to find it.
Code: Select all
Procedure ROTATE_90(image, dir)
; rotate image +/- 90 deg.
; 'image' is the number of the image to rotate
; if 'dir' = 0 then rotate left else rotate right
Protected a,b,c,e,f,h,s,w,x,y,ym,xm,tempImg,depth
If IsImage(image) = 0 : ProcedureReturn 0 : EndIf
StartDrawing(ImageOutput(image))
w = OutputWidth()
h = OutputHeight()
f = DrawingBufferPixelFormat() & $7F
StopDrawing()
If f = #PB_PixelFormat_32Bits_RGB Or f = #PB_PixelFormat_32Bits_BGR
depth = 32
ElseIf f = #PB_PixelFormat_24Bits_RGB Or f = #PB_PixelFormat_24Bits_BGR
depth = 24
Else
ProcedureReturn 0
EndIf
If w > h : s = w : Else : s = h : EndIf ; find the largest dimension
tempImg = CreateImage(#PB_Any,s,s,depth) ; make a square working area
StartDrawing(ImageOutput(tempImg))
If depth = 32 : DrawingMode(#PB_2DDrawing_AllChannels) : EndIf
DrawImage(ImageID(image),0,0)
ym = s/2-1 ; max y loop value
xm = s/2-(s!1&1) ; max x value, subtract 1 if 's' is even
s-1
If dir <> 0 ; rotate right
For y = 0 To ym
For x = 0 To xm
e = Point(x,y)
a = s-x : Plot(x,y,Point(y,a))
b = s-y : Plot(y,a,Point(a,b))
c = s-a : Plot(a,b,Point(b,c))
Plot(b,c,e)
Next x
Next y
Else ; rotate left
For y = 0 To ym
For x = 0 To xm
e = Point(x,y)
a = s-y : Plot(x,y,Point(a,x))
b = s-x : Plot(a,x,Point(b,a))
c = s-a : Plot(b,a,Point(c,b))
Plot(c,b,e)
Next x
Next y
EndIf
StopDrawing()
If dir <> 0
GrabImage(tempImg,image,s-h+1,0,h,w) ; right
Else
GrabImage(tempImg,image,0,s-w+1,h,w) ; left
EndIf
FreeImage(tempImg)
ProcedureReturn 1
EndProcedure
Here is one that uses direct image buffer access so it will be a little faster.
http://www.purebasic.fr/english/viewtop ... 00#p438200
Keep in mind Wilbert's warning on this one though.
http://www.purebasic.fr/english/viewtop ... 85#p437885