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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
;
; ------------------------------------------------------------
;
;   charger une image en streaming en local puis l'afficher by klr128
;   avec l'image redimentionné ;encodage et decodage base64 pour envoi blob mysql
; ------------------------------------------------------------
;
;EnableExplicit
 
Procedure CatchImageExCallback(Image)
  ImageGadget(#PB_Any, 0, 90, ImageWidth(Image), ImageHeight(Image), ImageID(Image))
EndProcedure
 
Procedure CatchImageEx(Image, Base64String.s, Callback) 
  Protected W, H, IID
  ! var i = new Image();
  ! i.onload = function(){
  !   v_w = i.width;
  !   v_h = i.height;
  If Image = #PB_Any
    Image = CreateImage(#PB_Any, W, H)
  Else
    CreateImage(Image, W, H)
  EndIf
  IID = ImageID(Image)
  !   v_iid.getContext("2d").drawImage(i, 0, 0);
  !   v_callback(v_image);
  ! };
  ! console.log("hahassss "+v_base64string);
  ! i.src = v_base64string; 
EndProcedure
 
Procedure Loaded(Type, Filename$, ObjectId)
  If ImageWidth(ObjectId)>=ImageHeight(ObjectId)
    vv.f= 300*100/ImageWidth(ObjectId)
    ResizeImage(bob, 300, ImageHeight(ObjectId)*vv/100);,#PB_Image_Raw)
  Else
    vv.f= (380 -90)*100/ImageHeight(ObjectId)    
    ResizeImage(bob, ImageWidth(ObjectId)*vv/100, (380-90))
  EndIf
  ;  bob=ImageGadget(#PB_Any, 0, 90, ImageWidth(ObjectId), ImageHeight(ObjectId), ImageID(ObjectId))
  IDD = ImageID(ObjectId)
  ;Debug "bob "+ImageID(bob)
  ;Debug "e "+IDD
  base64encodeimg.s = "";
  !  console.log( v_idd ); 
  ! console.log( v_idd.toDataURL() );
  ! v_base64encodeimg = v_idd.toDataURL();
  FreeImage(bob)  
  CatchImageEx(0, base64encodeimg, @CatchImageExCallback())
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
      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())