Code : Tout sélectionner
Procedure.i ImageRotation(filename.s, filedest.s, angle.f)
;- ATTENTION : AVEC #PB_Image_Transparent, IL Y A UN BUG D'AFFICHAGE SOUS WINDOWS, UNE LIGNE DE PIXEL A DROITE ET UNE EN BAS NE SONT PAS REMPLIES
CompilerIf #PB_Compiler_Debugger
Define.i itimer = ElapsedMilliseconds()
CompilerEndIf
Protected.s fileresult
Protected.i entrysize = FileSize(filename)
If entrysize <> -1 And entrysize <> -2 And entrysize > 0
Protected.i image = LoadImage(#PB_Any, filename)
If IsImage(image)
Protected.d CosA, SinA
Protected.d height, width, temp, img_w, img_h, cx, cy, w2, h2
CosA = Cos (Radian (angle))
SinA = Sin (Radian (angle))
width = ImageWidth (Image )
height = ImageHeight (Image )
img_w = Abs(height * SinA) + Abs(width * CosA)
img_h = Abs(height * CosA) + Abs(width * SinA)
cx=img_w/2:cy=img_h/2
w2=width/2:h2=height/2
; temp = CreateImage(#PB_Any, img_w, img_h, 32, #PB_Image_Transparent);Bug d'affichage
temp = CreateImage(#PB_Any, img_w, img_h, 24, RGB(255,255,255));
If IsImage(temp)
If StartVectorDrawing(ImageVectorOutput(temp))
RotateCoordinates (cx, cy, angle)
MovePathCursor (cx-w2,cy-h2)
DrawVectorImage (ImageID(image))
StopVectorDrawing ()
EndIf
; If SaveImage(temp, filedest, #PB_ImagePlugin_JPEG, QualityCompress, 24)
; fileresult = filedest
; EndIf
;; FreeImage(temp)
EndIf
FreeImage(image)
EndIf
EndIf
CompilerIf #PB_Compiler_Debugger
; Debug "ROTATION : " + FormatDate("%hh:%ii:%ss", (ElapsedMilliseconds() - itimer) / 1000)
; Debug "FILENAME : " + filename
CompilerEndIf
ProcedureReturn temp;fileresult
EndProcedure
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Enumeration FormWindow
#Window_0
EndEnumeration
Enumeration FormGadget
#Canvas_1
#Canvas_2
#ScrollArea_0
#ScrollArea_1
#Splitter_0
EndEnumeration
Declare ResizeGadgetsWindow_0()
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu)
ScrollAreaGadget(#ScrollArea_0, 0, 0, 600, 400, 1000, 1000, 10)
CanvasGadget(#Canvas_1, 0, 0, 1000, 1000)
CloseGadgetList()
ScrollAreaGadget(#ScrollArea_1, 159, 0, 600, 400, 1000, 1000, 10)
CanvasGadget(#Canvas_2, 0, 0, 1000, 1000)
CloseGadgetList()
SplitterGadget(#Splitter_0, 0, 0, 600, 400, #ScrollArea_0, #ScrollArea_1, #PB_Splitter_Vertical)
SetGadgetState(#Splitter_0, 200)
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(#Window_0)
FormWindowHeight = WindowHeight(#Window_0)
ResizeGadget(#Splitter_0, 0, 0, FormWindowWidth - 6, FormWindowHeight -10)
; ResizeGadget(#Canvas_1, 0, 0, GadgetWidth(#ScrollArea_0) - 0, GadgetHeight(#ScrollArea_0) - 0)
; ResizeGadget(#Canvas_2, 0, 0, GadgetWidth(#ScrollArea_1) - 0, GadgetHeight(#ScrollArea_1) - 0)
; ResizeGadget(#ScrollArea_0, 0, 0, FormWindowWidth - 0, FormWindowHeight - 0)
; ResizeGadget(#ScrollArea_1, 0, 0, FormWindowWidth - 0, FormWindowHeight - 0)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
;- Point d'entrée
OpenWindow_0(0,0,600,400)
SetWindowState(0,#PB_Window_Maximize)
File$="f:\1c.bmp"
If FileSize(File$) = -1
Debug "Fichier inexistant."
DebuggerError("Fichier inexistant.")
EndIf
;Originale
imgg=LoadImage(#PB_Any,File$)
If StartVectorDrawing(CanvasVectorOutput(#Canvas_1))
; ResetCoordinates()
MovePathCursor(10, 10)
DrawVectorImage(ImageID(imgg))
StopVectorDrawing()
EndIf
;Rotation
img=ImageRotation(File$, "", 120.0)
If StartVectorDrawing(CanvasVectorOutput(#Canvas_2))
; ResetCoordinates()
MovePathCursor(250, 250)
DrawVectorImage(ImageID(img))
;
StopVectorDrawing()
EndIf
;- Boucle
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
EndSelect
Until Event = #PB_Event_CloseWindow