none
LDWebCam.SnapshotToFile question RRS feed

Answers

  • Zock,

    I traced a problem with the image creating - image trying to be saved before it was fully created due to some delays in windows messaging - my bug.  This issue for some reason didn't show itself when the LDWebCam.SnapshotToFile was run from a button event - the guts of windows messaging somewhere.

    Updated version of LitDev extension (version 1.0.0.27) uploaded - sample code below should work as expected.  Save the SB file somewhere before running since the files are written to the Program.Directory folder.

    GraphicsWindow.Width = 700
    GraphicsWindow.Height = 280
    
    webcam = LDWebCam.Start(320,240)
    Shapes.Move(webcam,20,20)
    
    Timer.Interval = 1000
    Timer.Tick = OnTick
    
    Sub OnTick
      fileName = Program.Directory+"\"+Math.Floor(Clock.ElapsedMilliseconds)+".jpg"
      LDWebCam.SnapshotToFile(fileName)
      GraphicsWindow.DrawResizedImage(fileName,360,20,320,240)
    EndSub

    Thursday, August 16, 2012 8:00 PM
    Moderator

All replies

  • In the sample file (webcam.sb), replacing LDWebCam.Snapshot() with LDWebCam.SnapshotToFile("C:\temp\myfile.png") works for me, assuming C:\temp exists, or LDWebCam.SnapshotToFile(Program.Directory+"\mySnapshot.jpg") for a jpg saved in the source folder.
    Monday, August 13, 2012 10:06 PM
    Moderator
  • I can' t get it to just save a img.

    Can you make it take a pic then draw it on the graphicswindow?


    Zock77


    • Edited by Zock77Editor Wednesday, August 15, 2012 10:58 PM
    Wednesday, August 15, 2012 10:54 PM
    Answerer
  • Try this.   click photo button.  A  photo like this  "20120816_211530.jpg"  is saved .

    init()

    Controls.ButtonClicked = OnButtonClicked

    Sub OnButtonClicked
      If (Controls.LastClickedButton = picture) Then
        Controls.HideControl(picture)
        ct=text.Append(text.Append(Clock.hour,Clock.Minute),Clock.Second)
        Shapes.SetText(smsg,dt+"_"+ct)
        LDUtilities.PauseUpdates()                      '   Pause
        PGF=program.Directory+"\" +dt+"_"+ct+".jpg"
        LDUtilities.GWCapture(PGF,"False")
        LDUtilities.ResumeUpdates()                    '  resume  
        Controls.showControl(picture)
      EndIf
    EndSUb

    Sub init
      GW=1000
      GH=650
      GraphicsWindow.Top=20
      GraphicsWindow.Left=50
      GraphicsWindow.Width = GW
      GraphicsWindow.Height = GH
     
      GraphicsWindow.BackgroundColor = LDColours.AntiqueWhite
      webcam = LDWebCam.Start(GW-20,GH-20)   '  <----------   web   
      Shapes.Move(webcam,10,10)
      GraphicsWindow.BrushColor="Yellow"
      picture = Controls.AddButton("Photo",GW-60,GH-35)
      Controls.SetSize(picture,50,28)
      smsg= Shapes.AddText("  ")
      Shapes.Move(smsg,GW-175,GH-30)
      dt=text.Append(text.Append(Clock.Year,Clock.month),Clock.Day)
      Shapes.SetText(smsg,dt+"_XXYYZZ")
    EndSub

    * This method is an  another way to get snapshot.


    Thursday, August 16, 2012 12:18 PM
    Answerer
  • What I'm trying to do seems pretty simple.

    I am trying to save a pic from the webcam, then show it with graphicswindow.drawtext. so I can do a pixel check to attempt movement detection.


    One thing that is impossible is impossible no matter if it is proven so first.

    Thursday, August 16, 2012 3:34 PM
    Answerer
  •  

    Try this .   Add  these 4 lines.

       Controls.showControl(picture)
       LDWebCam.End()
       Shapes.Remove(webcam)
       loadpic= ImageList.LoadImage(PGF)
       GraphicsWindow.DrawResizedImage(loadpic,0,0,400,300)

    Thursday, August 16, 2012 4:00 PM
    Answerer
  • Zock,

    I traced a problem with the image creating - image trying to be saved before it was fully created due to some delays in windows messaging - my bug.  This issue for some reason didn't show itself when the LDWebCam.SnapshotToFile was run from a button event - the guts of windows messaging somewhere.

    Updated version of LitDev extension (version 1.0.0.27) uploaded - sample code below should work as expected.  Save the SB file somewhere before running since the files are written to the Program.Directory folder.

    GraphicsWindow.Width = 700
    GraphicsWindow.Height = 280
    
    webcam = LDWebCam.Start(320,240)
    Shapes.Move(webcam,20,20)
    
    Timer.Interval = 1000
    Timer.Tick = OnTick
    
    Sub OnTick
      fileName = Program.Directory+"\"+Math.Floor(Clock.ElapsedMilliseconds)+".jpg"
      LDWebCam.SnapshotToFile(fileName)
      GraphicsWindow.DrawResizedImage(fileName,360,20,320,240)
    EndSub

    Thursday, August 16, 2012 8:00 PM
    Moderator
  • Thank you so much!!

    That is exactly what I wanted!


    One thing that is impossible is impossible no matter if it is proven so first.

    Thursday, August 16, 2012 8:37 PM
    Answerer
  • I liked your motion detection idea and added some image processing methods to help in LDImage (Version 1.0.0.28 uploaded).  Example using this, import BNZ691.
    Saturday, August 18, 2012 9:41 AM
    Moderator
  • Yeah. checking the pixels take a while.

    One thing that is impossible is impossible no matter if it is proven so first.

    Saturday, August 18, 2012 3:35 PM
    Answerer