Page 1 of 1

rename cam images

Posted: Wed Sep 29, 2004 11:45 pm
by Rebe
I found this on the CodeArchiv , could someone help me .i want it to save the pictures and rename them with a number so they are all saved as it refreshs .
Thank you for the help

Code: Select all

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=2015&highlight=
; Author: Danilo
; Date: 18. August 2003


; #page.s defines the address of the image to load
; #page.s definiert die Adresse des zu ladenden Bildes
Procedure UpdateImage() 
  #page.s = "http://media.g4techtv.com/images/webcam/tss/sarah.jpg"   ; there is probably only every xx minutes a new picture on the server !
  DeleteUrlCacheEntry_(#page) 
  URLDownloadToFile_(0,#page, "c:\__temp.jpg", 0, 0) 
  LoadImage(0, "c:\__temp.jpg") 
  DeleteFile("c:\__temp.jpg") 
  If GadgetID(0) 
    SetGadgetState(0,UseImage(0)) 
  EndIf 
EndProcedure 

UseJPEGImageDecoder() 

UpdateImage() 

OpenWindow(0, 0, 0, ImageWidth(), ImageHeight(), #PB_Window_SystemMenu, "PB - Webcam!") 
  CreateGadgetList(WindowID()) 
  ImageGadget(0,0,0,ImageWidth(),ImageHeight(),ImageID(),#PB_Image_Border) 

SetTimer_(WindowID(),1,10000,0) 

Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow 
      End 
    Case #WM_TIMER 
      UpDateImage() 
      Beep_(800,50) 
  EndSelect 
ForEver 

Posted: Thu Sep 30, 2004 2:33 am
by Sparkie
First thing that comes to mind is using current date/time for the file name. Just be sure to change the file extension as needed. :wink: This example uses .jpg for the image in your example.

Code: Select all

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=2015&highlight= 
; Author: Danilo 
; Date: 18. August 2003 

; --> ; slightly modified code below is based on theoriginal code

; #page.s defines the address of the image to load 
; #page.s definiert die Adresse des zu ladenden Bildes 
Procedure UpdateImage() 
  #page.s = "http://media.g4techtv.com/images/webcam/tss/sarah.jpg"   ; there is probably only every xx minutes a new picture on the server ! 
  DeleteUrlCacheEntry_(#page) 
  
  ; --> here we use the current date/time for the file name
  filename$ = FormatDate("c:\%mm%dd%yy%hh%mm%ss.jpg", Date())
  URLDownloadToFile_(0,#page, filename$, 0, 0) 
  LoadImage(0, filename$) 
  ; <--
  
  ; --> we don't want to delete the file
  ;DeleteFile("c:\__temp.jpg") 
  
  ; --> changed to use new IsGadget() function (PB 3.91)
  If IsGadget(0) 
    SetGadgetState(0,UseImage(0)) 
  EndIf 
EndProcedure 

UseJPEGImageDecoder() 

UpdateImage() 

OpenWindow(0, 0, 0, ImageWidth(), ImageHeight(), #PB_Window_SystemMenu, "PB - Webcam!") 
CreateGadgetList(WindowID()) 
ImageGadget(0,0,0,ImageWidth(),ImageHeight(),ImageID(),#PB_Image_Border) 

SetTimer_(WindowID(),1,10000,0) 

Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow 
      End 
    Case #WM_TIMER 
      UpdateImage() 
      Beep_(800,50) 
  EndSelect 
ForEver 

Posted: Thu Sep 30, 2004 2:42 am
by Rebe
Got this when I try to run it ?
---------------------------
PureBasic
---------------------------
Line 23: IsGadget() is not a function, an array, or a linked list

How do I fix that ?

Posted: Thu Sep 30, 2004 2:45 am
by Sparkie
I replaced this

Code: Select all

If GadgetID(0) 
    SetGadgetState(0,UseImage(0)) 
  EndIf 
with this

Code: Select all

If IsGadget(0) 
    SetGadgetState(0,UseImage(0)) 
  EndIf 

IsGadget() is for PB 3.91 so either upgrade or put the original code back in place. :)

Posted: Thu Sep 30, 2004 2:50 am
by Rebe
Yes I had just changed that and it is working now . thank you for your help .