CatchImage

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
User avatar
Paul
Posts: 115
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

CatchImage

Post by Paul »

Please add CatchImage function like in PureBasic.

In PureBasic you can send a Base64 encoded image and then decode and display it like this...
It would make perfect sense to have the same functionality in SpiderBasic.

(and how about native Base64Encoder/Decoder while we're at it ) ;)

Code: Select all

pic.s="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" 

UsePNGImageDecoder()
If OpenWindow(0,0,0,200,100,"Pic",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)  
  *buf=AllocateMemory(Len(pic))
  l=Base64Decoder(pic, *buf, MemorySize(*buf))
  CatchImage(1,*buf,l)
  FreeMemory(*buf)
  ImageGadget(1,0,0,200,100,ImageID(1))
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
User avatar
Peter
Posts: 888
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: CatchImage

Post by Peter »

Paul wrote:Please add CatchImage function like in PureBasic.
+1

Until then, here is a solution that you could work with:

Code: Select all

EnableExplicit

Define pic.s

pic="iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFv0lEQVRYw61XeUxUZxB/arX+Yf8kadImp"+
    "IlpUtM0abRHrBVr0oaqUAXBiIKKXLqAIscCi4LgUhR2OVbEC7kPORVMDSJqKx5QS1srSNGmVFBQ8MAt+8"+
    "7d6Tff6naXfYscTjIJj/3eN7+Z+c3xGGYSUuXlNWsofPXCpxGegSO7/VP1Gbvy9JqovJHErWmPd3qGDOx"+
    "w/+xI0MLZzOuWvnC3j/RpO/LYkswhvigD+MJ04I6kAJelNOuRZPo//I2ceaJPj8wfUrgvmrbhB9s9nPWZ"+
    "ymquNMvE5e4BQ7Q3GKK8XqmcLh740izQZ6vO9CtWvz8l4w8j1/mypdnPuZz4CRmVBZIZA2xZjuFxrE8Iu"+
    "XLGRG3PeJwUqO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LHCapy/SPJcDgC1X6mh9AcYHTM+GZQHwxZnAqh"+
    "WW/k/TgdFD0GSG0FIcc/9ooYaPWzLfiXbDe3sVJzmdyj4CLzyypOPgbppzG+8vNdrNA8y95R1NtJlD1gQ"+
    "kwPrTo5ssA6lp7ZfLcUDIccBu0pGqwEYjXmwgXTFR9ow1HxwNo8sbvl5jPY1n9adFXsId7lUAJqJCzTGH"+
    "05A9sBMGMuM7iE3b9b3cffGi0dIsDne46QLgDqeYuXFUbQsghpR1uU6s9/ximexW1B7kFo8L5HQBmIlYQ"+
    "ZbRPNuVrFwHHWFrD4y3F77RHbO5FBfI17mQUuPFGribENwwn2HeHHcrdnZm5nZG+1XQzZj0gWkbJ2FHz+"+
    "+oghpdnJzmTfTbYHZrwKrk0bJsgS6jUzSOhDOU5Uht2zy0zgwzd7IfRzMOr/hkaW9a5M9YNrhGTdgwqXN"+
    "8py8j9mbhqk+/mcxXkZzMqfxuseefSaHn/y3M4OjHKVkmcJ7jREPFwYK9HX8jZ4SefTt+qvdY6sNMwevx"+
    "ZKbr/HfePe25ZP31za4Zt+K21txWR7TcVu9quaUKrGv3/1bbsNbF1+ODt53x7EQv/Q8P90ed9khbrwAAAABJRU5ErkJggg=="


Procedure CatchImageExCallback(Image)
  
  OpenWindow(#PB_Any, 10, 10, 300, 300, "Image", #PB_Window_SizeGadget)
  ImageGadget(#PB_Any, 0, 0, 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);
  ! };
  
  ! i.src = "data:image/png;base64," + v_base64string;
  
EndProcedure

CatchImageEx(0, pic, @CatchImageExCallback())
Greetings ... Peter
User avatar
Paul
Posts: 115
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: CatchImage

Post by Paul »

Peter wrote: Until then, here is a solution that you could work with.
Greetings ... Peter
Thanks very much Peter, for now that works perfect for what I need!!
Post Reply