Here is an example to show all frames from tiff file using GDI+
It opens the tiff and display each frame during a time (with a timer). Used Image is with GDI+ documentation.
It's extracted from my GDI+ documentation (the new version for PB 4.40 will come as soon as PB do the final version

), chm help file only in french but almost one example for each GDI+ function.
You must use the wrapper from my doc (or adapt it for you), dowload it from my first post here
http://www.purebasic.fr/english/viewtop ... us&start=0
For some reasons, some examples doesn't work anymore with PB 4.40 beta ../4/5/6
It 's already corrected but i'm wainting for PB 4.40 final version.
Code: Select all
XIncludeFile "..\..\gdiplus.pbi"
EnableExplicit
#MainWindow = 0
#TexteGadget = 0
#Timer = 10
#Police = 0
Define .i
Global *token, *Image, *dimensionID.GUID, dimensionsCount = 0, dimension.s = ""
Global count, Erreur = 0, OldProc, quit, Titre.s, timer = 800, Operation = -1
Procedure GDIpCallback(window, message, wParam, lParam)
Protected dc, ps.PAINTSTRUCT
Protected *Localtoken, *Localgfx
Protected color = ARGB(#White)
Select message
Case #WM_CLOSE
Gdiplus_DelImage(*image)
Gdiplus_Del(*token)
RemoveWindowTimer(#MainWindow, #Timer)
OldProc = SetWindowLong_(WindowID(#MainWindow), #GWL_WNDPROC, OldProc)
quit + 1
ProcedureReturn 0
Case #WM_PAINT
dc = BeginPaint_(window, @ps)
If dc
; initialisation de Gdi+
*Localtoken = Gdiplus_New()
; on vérifie que l'initialisation est Ok
If *Localtoken
; création du graphique source associé au DC de la fenêtre principale
If GdipCreateFromHDC(dc, @*Localgfx) = #Ok
If Operation> = count
Operation = 0
EndIf
GdipGraphicsClear(*Localgfx, color)
GdipImageSelectActiveFrame(*image, ?FrameDimensionPage, Operation)
GdipDrawImageI(*Localgfx, *image, 50, 50)
; supprime l'objet graphique principal
Gdiplus_DelGraphics(*Localgfx)
EndIf
Gdiplus_Del(*Localtoken)
EndIf
EndPaint_(window, @ps)
EndIf
ProcedureReturn 0
EndSelect
ProcedureReturn CallWindowProc_(OldProc, window, message, wParam, lParam)
EndProcedure
If OpenWindow(#MainWindow, 10, 10, 610, 540, "GdiPlus 1.0 - GdipImageGetFrameCount", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
AddWindowTimer(#MainWindow, #Timer, timer)
TextGadget(#TexteGadget, 60, 460, WindowWidth(#MainWindow)-60, 90, "")
LoadFont(#Police, "Arial", 12)
SetGadgetFontEx(#TexteGadget, #Police)
SetGadgetColor(#TexteGadget, #PB_Gadget_BackColor, #White)
; initialisation de Gdi+
*token = Gdiplus_New()
; on vérifie que l'initialisation est Ok
If *token
If GdipLoadImageFromFile("..\..\GdiPlusDatas\MultiFrame.tif", @*Image) = #Ok
; retrouve le nombre de dimensions de l'image tif
If GdipImageGetFrameDimensionsCount(*image, @dimensionsCount) = #Ok
If dimensionsCount
; allocation de mémoire pour stocker le/les idendifiants dimensionnel de l'image tif
*dimensionID = AllocateMemory(SizeOf(GUID)*dimensionsCount)
If *dimensionID
; retrouve la liste des dimensions de l'image tif
GdipImageGetFrameDimensionsList(*image, *dimensionID, dimensionsCount)
; teste le type dimensions de l'image tif (une seule dimension)
If CompareMemory(*dimensionID, ?FrameDimensionTime, SizeOf(GUID))
dimension = "FrameDimensionTime"
ElseIf CompareMemory(*dimensionID, ?FrameDimensionResolution, SizeOf(GUID))
dimension = "FrameDimensionResolution"
ElseIf CompareMemory(*dimensionID, ?FrameDimensionPage, SizeOf(GUID))
dimension = "FrameDimensionPage"
Else
dimension = "inconnue"
EndIf
; retrouve le nombre d'image de l'image tif
If GdipImageGetFrameCount(*image, ?FrameDimensionPage, @count) = #Ok
Titre = "Nombre de dimensions de l'image : " + Str(dimensionsCount) + Chr(10)
Titre + "Type de la dimension de l'image : " + dimension + Chr(10)
Titre + "Nombre d'images contenu dans le tif : " + Str(count)
; affiche les données
SetGadgetText(#TexteGadget, Titre)
EndIf
FreeMemory(*dimensionID)
EndIf
EndIf
EndIf
OldProc = SetWindowLong_(WindowID(#MainWindow), #GWL_WNDPROC, @GDIpCallback())
Else
Erreur + 1
EndIf
EndIf
; boucle
Repeat
If Erreur
MessageRequester("Erreur", "Impossible de charger l'image", 16)
Break
EndIf
Select WaitWindowEvent()
Case #PB_Event_Timer
Operation + 1
RedrawWindow_(WindowID(#MainWindow), 0, 0, 7)
Case #PB_Event_CloseWindow
quit + 1
Break
EndSelect
Until quit
EndIf
End