Code : Tout sélectionner
Prototype GdiplusStartup(a,b,c)
Prototype GdipDisposeImage(a)
Prototype GdiplusShutdown(a)
Prototype GdipLoadImageFromFile(a.s,b)
Prototype GdipGetEffectParameterSize(a,b)
Prototype GdipSetEffectParameters(a,b,c.l)
Prototype GdipDeleteEffect(a)
Prototype GdipBitmapApplyEffect(a,b.l,c,d.l,e,f)
Prototype GdipCreateEffect_x64(a,e)
Prototype GdipCreateEffect(a.q,b.q,e)
Prototype GdipCreateFromHWND(a,b)
Prototype GdipGetImageWidth(a,b)
Prototype GdipGetImageHeight(a,b)
Prototype GdipDrawImageRect(a,b,c.f,d.f,e.f,f.f)
Prototype GdipDeleteGraphics(a)
Global lib_gdiplus = OpenLibrary(#PB_Any, "GDIPlus.dll")
Global GdiplusStartup_.GdiplusStartup=GetFunction(lib_gdiplus,"GdiplusStartup")
Global GdiplusShutdown_.GdiplusShutdown=GetFunction(lib_gdiplus,"GdiplusShutdown")
Global GdipDisposeImage_.GdipDisposeImage=GetFunction(lib_gdiplus,"GdipDisposeImage")
Global GdipLoadImageFromFile_.GdipLoadImageFromFile=GetFunction(lib_gdiplus,"GdipLoadImageFromFile")
Global GdipGetEffectParameterSize_.GdipGetEffectParameterSize=GetFunction(lib_gdiplus,"GdipGetEffectParameterSize")
Global GdipSetEffectParameters_.GdipSetEffectParameters=GetFunction(lib_gdiplus,"GdipSetEffectParameters")
Global GdipBitmapApplyEffect_.GdipBitmapApplyEffect=GetFunction(lib_gdiplus,"GdipBitmapApplyEffect")
Global GdipDeleteEffect_.GdipDeleteEffect=GetFunction(lib_gdiplus,"GdipDeleteEffect")
Global GdipCreateEffect_x64_.GdipCreateEffect_x64=GetFunction(lib_gdiplus,"GdipCreateEffect")
Global GdipCreateEffect_.GdipCreateEffect=GetFunction(lib_gdiplus,"GdipCreateEffect")
Global GdipCreateFromHWND_.GdipCreateFromHWND=GetFunction(lib_gdiplus,"GdipCreateFromHWND")
Global GdipGetImageWidth_.GdipGetImageWidth=GetFunction(lib_gdiplus,"GdipGetImageWidth")
Global GdipGetImageHeight_.GdipGetImageHeight=GetFunction(lib_gdiplus,"GdipGetImageHeight")
Global GdipDrawImageRect_.GdipDrawImageRect=GetFunction(lib_gdiplus,"GdipDrawImageRect")
Global GdipDeleteGraphics_.GdipDeleteGraphics=GetFunction(lib_gdiplus,"GdipDeleteGraphics")
If Not lib_gdiplus Or Not GdipBitmapApplyEffect_
MessageBox_(0,"GDIPlus.dll v1.1 non disponible.","ERREUR :(!",#MB_ICONSTOP)
End
EndIf
Structure GDIP_EFFECTPARAMS_Blur
Radius.f
ExpandEdge.l
EndStructure
Structure GDIP_EFFECTPARAMS_Fix
it.q[2]
EndStructure
Structure GdiplusStartupInput
GdiPlusVersion.l
*EventCallback._EVENT
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
#GDIP_Ok=0
Procedure _Gdiplus_Startup()
Protected GdiplusStartupInput.GdiplusStartupInput\GdiPlusVersion=1
Protected token
If GdiplusStartup_(@token, @GdiplusStartupInput,0)=#GDIP_Ok
ProcedureReturn token
EndIf
EndProcedure
Procedure Gdiplus_GetImageWidth(hImage)
Protected xw:GdipGetImageWidth_(hImage,@xw):ProcedureReturn xw
EndProcedure
Procedure Gdiplus_GetImageHeight(hImage)
Protected xy:GdipGetImageHeight_(hImage,@xy):ProcedureReturn xy
EndProcedure
Global Gdiplus_Startup = _Gdiplus_Startup()
If Not Gdiplus_Startup
Debug "Error ====> _Gdiplus_Startup()"
End
EndIf
Declare _Selectimage()
Global GdipEffect,himage,hGraphics
OpenWindow(0, 0, 0, 600, 400, "Test_GdipBitmapCreateApplyEffect", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 120, 25, "Choisissez Une image")
BindGadgetEvent(0,@_Selectimage())
ImageGadget(1, 10, 50, 580, 340, 0)
TextGadget(2, 140, 15, 460, 25, "...")
Repeat:If WaitWindowEvent() = #PB_Event_CloseWindow:Break:EndIf:ForEver
Procedure Clean_Gdip_BEffect()
If himage:GdipDisposeImage_(himage):EndIf
If hGraphics:GdipDeleteGraphics_(hGraphics):EndIf
If GdipEffect:GdipDeleteEffect_(GdipEffect):EndIf
GdipEffect=0:hGraphics=0:himage=0
EndProcedure
Clean_Gdip_BEffect()
GdiplusShutdown_(Gdiplus_Startup)
Procedure _Selectimage()
Protected Fichier$ = OpenFileRequester("Choisissez Une image", "", "Image |*.bmp;*.png;*.jpg;*.gif;*.tif",0)
If Fichier$ = #NUL$
ProcedureReturn
EndIf
SetGadgetText(2,Fichier$)
Clean_Gdip_BEffect()
GdipLoadImageFromFile_(Fichier$,@himage)
GdipCreateFromHWND_(GadgetID(1),@hGraphics)
CompilerIf #PB_Compiler_Processor=#PB_Processor_x64
GdipCreateEffect_x64_(?GDIP_BlurEffectGuid,@GdipEffect)
CompilerElse
*GDIP_EFFECTPARAMS_Fix.GDIP_EFFECTPARAMS_Fix=?GDIP_BlurEffectGuid
GdipCreateEffect_(*GDIP_EFFECTPARAMS_Fix\it[0],*GDIP_EFFECTPARAMS_Fix\it[1],@GdipEffect)
CompilerEndIf
Protected effetpar.GDIP_EFFECTPARAMS_Blur\Radius=10.0 ,isize
GdipGetEffectParameterSize_(GdipEffect,@isize)
GdipSetEffectParameters_(GdipEffect,@effetpar,isize)
GdipBitmapApplyEffect_(himage,GdipEffect,0,0,0,0)
GdipDrawImageRect_(hGraphics,himage,0,0,Gdiplus_GetImageWidth(himage),Gdiplus_GetImageHeight(himage))
EndProcedure
DataSection
GDIP_BlurEffectGuid: ; GDI+ effect GUIDs
Data.l $633C80A4
Data.w $1843
Data.w $482b
Data.b $9E,$F2,$BE,$28,$34,$C5,$FD,$D4
EndDataSection