GDIPlus effets de flou sur une image!!!

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

GDIPlus effets de flou sur une image!!!

Message par celtic88 »

:roll:

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
.....i Love Pb :)
Avatar de l’utilisateur
Micoute
Messages : 2522
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: GDIPlus effets de flou sur une image!!!

Message par Micoute »

Du bon travail comme d'habitude, juste une petite erreur de frappe à la ligne 99, remplacer #Nul$ par #Null$, c'est vraiment minime comme erreur.

Génial, j'adore, j'adhère et j'adopte.
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 5.73 PB 6.00 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Re: GDIPlus effets de flou sur une image!!!

Message par GallyHC »

Bonjour,

Micoute > je ne pense pas que ce soit une faute de frappe "#Nul$" existe bien avec les versions inferieurs à la 5.4x de PB (et a disparu a cette version aussi).

Cordialement,
GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: GDIPlus effets de flou sur une image!!!

Message par celtic88 »

merci à vous .
c'était juste un exemple vite fait il ya d'autre effets je vais essayer de les mettre ici,, si j ai plus de temp ...

amusez vous bien :wink:
.....i Love Pb :)
Répondre