Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;
; ------------------------------------------------------------
;
;   charger une image en streaming en local puis l'afficher by klr128
;   avec l'image redimentionné
; ------------------------------------------------------------
;
 
Procedure Loaded(Type, Filename$, ObjectId)
  vv.f= 300*100/ImageWidth(ObjectId)
  ResizeImage(bob, 300, ImageHeight(ObjectId)*vv/100);,#PB_Image_Raw)
  bob=ImageGadget(#PB_Any, 0, 90, ImageWidth(ObjectId), ImageHeight(ObjectId), ImageID(ObjectId))
EndProcedure
 
Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
EndProcedure
 
Enumeration
  #SelectFileGadget
  #ProgressGadget
EndEnumeration
 
#ChunkSize = 1024 * 1024 ; 1 MB chunk
Global *Buffer = AllocateMemory(#ChunkSize) ; Allocate a global memory buffer to avoid realloc
 
Procedure ReadCallback(Status, Filename$, File, Size)
  If Status = #PB_Status_Loaded
    ReadData(0, *Buffer, 0, Size)    ; Read all data into the memory buffer
    AddFingerprintBuffer(0, *Buffer, 0, Size)    ; Continue the fingerprint calculation    
    SetGadgetState(#ProgressGadget, (Loc(0) * 100) / Lof(0))    ; Update the progressbar  
    If Not Eof(0)
      FetchData(0, #ChunkSize) ; Continue the reading if the end of file hasn't be reach yet
    Else
      ;Debug "MD5 Result:" + FinishFingerprint(0) ; Display the MD5 result
      LoadImage(0, Filename$,#PB_LocalFile);"Data/SpiderBasicLogo.png")
    EndIf
  ElseIf Status = #PB_Status_Error
    Debug "Error when loading the file: " + Filename$
  EndIf
EndProcedure
 
Procedure OpenFileRequesterCallback()  ; Start the read the file, in stream mode
  If NextSelectedFile()
    If ReadFile(0, SelectedFileID(), @ReadCallback(), #PB_LocalFile | #PB_File_Streaming)
      StartFingerprint(0, #PB_Cipher_MD5)      ; Initialize fingerprint calc
      FetchData(0, #ChunkSize)       ; Read the first chunk from the file
    EndIf 
  EndIf
EndProcedure
 
Procedure ChooseFileEvent()
  OpenFileRequester("*.txt", @OpenFileRequesterCallback())
EndProcedure
 
If OpenWindow(0, 0, 0, 300, 380, "charger une image par morceaux", #PB_Window_ScreenCentered)
  ButtonGadget(#SelectFileGadget, 10, 10, 280, 25, "charger une image")
  TextGadget(#PB_Any, 10, 45, 60, 25, "Progression: ")
  ProgressBarGadget(#ProgressGadget, 70, 45, 220, 25, 0, 100)
 
  BindGadgetEvent(0, @ChooseFileEvent())
EndIf
 
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())