Loading a picure on the fly

Just starting out? Need help? Post your questions and find answers here.
Stefan
Posts: 160
Joined: Mon Feb 05, 2018 9:44 pm

Loading a picure on the fly

Post by Stefan »

Is there a possibility to load pictures on the fly?
At the moment I know only code to load images at program start.
Alexander
Posts: 5
Joined: Wed Feb 07, 2018 10:34 am

Re: Loading a picure on the fly

Post by Alexander »

Hello Stefan, something like this:

Code: Select all

Procedure Loaded(Type, Filename$, ObjectId)
  Debug "Loading image: " + Filename$
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
EndProcedure

BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())

OpenWindow(0, 0, 0, 320, 200, "Image", #PB_Window_ScreenCentered)
CanvasGadget(1, 10, 10, 180, 180)
ButtonGadget(2, 220, 20, 80, 20, "Load image 1")
ButtonGadget(3, 220, 50, 80, 20, "Load image 2")
ButtonGadget(4, 220, 100, 80, 20, "View image 1")
ButtonGadget(5, 220, 130, 80, 20, "View image 2")

Procedure GadgetEvent()
  Select EventGadget()
    Case 2
      LoadImage(11, "https://www.spiderbasic.com/img/logo.png")
    Case 3
      LoadImage(12, "http://forums.spiderbasic.com/styles/anami/imageset/spiderbasic.png")
    Case 4
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(11), 0, 0)
      StopDrawing()
    Case 5
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(12), 0, 50)
      StopDrawing()
  EndSelect
EndProcedure

BindEvent(#PB_Event_Gadget, @GadgetEvent())
Stefan
Posts: 160
Joined: Mon Feb 05, 2018 9:44 pm

Re: Loading a picure on the fly

Post by Stefan »

The problem here is, you need two steps to show a picture.
Step 1 to push a button to load a picture and
Step 2 to show this picture.

I need a way to do this in 1 step, to load a picture and to show it immediately without any more steps.
Alexander
Posts: 5
Joined: Wed Feb 07, 2018 10:34 am

Re: Loading a picure on the fly

Post by Alexander »

Use timer.
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: Loading a picure on the fly

Post by Dirk Geppert »

Code: Select all

Procedure Loaded(Type, Filename$, ObjectId)
  Select ObjectId
    Case 11      
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(11), 0, 0)
      StopDrawing()
    Case 12
      StartDrawing(CanvasOutput(1))
      DrawImage(ImageID(12), 0, 50)
      StopDrawing()
  EndSelect
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
EndProcedure

BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())

OpenWindow(0, 0, 0, 320, 200, "Image", #PB_Window_ScreenCentered)
CanvasGadget(1, 10, 10, 180, 180)
ButtonGadget(2, 220, 20, 80, 20, "Load image 1")
ButtonGadget(3, 220, 50, 80, 20, "Load image 2")

Procedure GadgetEvent()
  Select EventGadget()
    Case 2
      LoadImage(11, "https://www.spiderbasic.com/img/logo.png")
    Case 3
      LoadImage(12, "http://forums.spiderbasic.com/styles/anami/imageset/spiderbasic.png")

  EndSelect
EndProcedure

BindEvent(#PB_Event_Gadget, @GadgetEvent())
Post Reply