Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# for non C# programmer

C# for non C# programmer

Scheduled Pinned Locked Moved C#
csharpgraphicsquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    matty2desmara
    wrote on last edited by
    #1

    Hi, I'm not fluent with C# (but i some how got forced into doing this). After form1 loads the user supplies information (Ip address, username ...etc), presses button 1, this connects them to a specialized video recorder. I then call the ExportImage() method to save the current frame to a bmp in a specified location. What i would like to do is automatically go to ExportImage() every 5 seconds. The only way i can get it to call ExportImage() again is to press the button. Any suggestions? Thanks Matt

    static void Main()
    {
    Application.Run(new Form1());

    	}
    
    
    
        private void button1\_Click(object sender, System.EventArgs e)
        {
    
            
    
            IDVRSystem system = SystemFactory.FindOrCreateSystem(cmbSystem.Text, 18772, txtUserID.Text, txtPassword.Text);
            system.Open();
            if (system.ConnectionStatus == Integral.Client.Sources.ConnectionState.LoggedIn)
            {
    
                mRecorder = system.Recorders.FindByIPAddress(txtRecorder.Text);
                if (mRecorder != null)
                {
    
                    // Sometimes a camera is not renderable because it is not 'detected.'
                    // we'll just keep rendering until we get a successful render.
                    foreach (IStream stream in mRecorder.Cameras)
                    {
                        mInfo = stream.Render(picVideo);
    
    
                           if (mInfo != null)
    
                             break;
                    }
    
                    //Console.WriteLine("button method");
    
                    //ExportImage();
    
                }
    
            }
    
    
        }
        
        
        private void ExportImage()
    	{
    
            Console.WriteLine("Export Image Method");
    
            Bitmap bmp;
            double aspectRatio;
    
            
                System.Threading.Thread.Sleep(500);
    
                mInfo.VideoOverlay.GetCurrentImage(false, out bmp, out aspectRatio);
                Image img = bmp.GetThumbnailImage(800, 600, null, IntPtr.Zero);
                img.Save(@"C:\\Test.bmp");
                img.Dispose();
                bmp.Dispose();
            
            
          }
    
    M 1 Reply Last reply
    0
    • M matty2desmara

      Hi, I'm not fluent with C# (but i some how got forced into doing this). After form1 loads the user supplies information (Ip address, username ...etc), presses button 1, this connects them to a specialized video recorder. I then call the ExportImage() method to save the current frame to a bmp in a specified location. What i would like to do is automatically go to ExportImage() every 5 seconds. The only way i can get it to call ExportImage() again is to press the button. Any suggestions? Thanks Matt

      static void Main()
      {
      Application.Run(new Form1());

      	}
      
      
      
          private void button1\_Click(object sender, System.EventArgs e)
          {
      
              
      
              IDVRSystem system = SystemFactory.FindOrCreateSystem(cmbSystem.Text, 18772, txtUserID.Text, txtPassword.Text);
              system.Open();
              if (system.ConnectionStatus == Integral.Client.Sources.ConnectionState.LoggedIn)
              {
      
                  mRecorder = system.Recorders.FindByIPAddress(txtRecorder.Text);
                  if (mRecorder != null)
                  {
      
                      // Sometimes a camera is not renderable because it is not 'detected.'
                      // we'll just keep rendering until we get a successful render.
                      foreach (IStream stream in mRecorder.Cameras)
                      {
                          mInfo = stream.Render(picVideo);
      
      
                             if (mInfo != null)
      
                               break;
                      }
      
                      //Console.WriteLine("button method");
      
                      //ExportImage();
      
                  }
      
              }
      
      
          }
          
          
          private void ExportImage()
      	{
      
              Console.WriteLine("Export Image Method");
      
              Bitmap bmp;
              double aspectRatio;
      
              
                  System.Threading.Thread.Sleep(500);
      
                  mInfo.VideoOverlay.GetCurrentImage(false, out bmp, out aspectRatio);
                  Image img = bmp.GetThumbnailImage(800, 600, null, IntPtr.Zero);
                  img.Save(@"C:\\Test.bmp");
                  img.Dispose();
                  bmp.Dispose();
              
              
            }
      
      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      matty2desmara wrote:

      What i would like to do is automatically go to ExportImage() every 5 seconds.

      Look up the different Timer classes in MSDN or Google. The System.Windows.Forms Timer class. Marc

      Will work for food. Interacx

      M 1 Reply Last reply
      0
      • M Marc Clifton

        matty2desmara wrote:

        What i would like to do is automatically go to ExportImage() every 5 seconds.

        Look up the different Timer classes in MSDN or Google. The System.Windows.Forms Timer class. Marc

        Will work for food. Interacx

        M Offline
        M Offline
        matty2desmara
        wrote on last edited by
        #3

        Hi Marc, I forgot to include that in my code, but i was trying to use Thread.Sleep(time) with no success. I'm not sure where to put it. I think my main issue is getting exportImage() to be called more than once, since it's in the foreach loop i though it would be called on every scan, do you know why it's not ? the only way i can initiate a call again is to press button1. Thanks for your help Matt

        M 1 Reply Last reply
        0
        • M matty2desmara

          Hi Marc, I forgot to include that in my code, but i was trying to use Thread.Sleep(time) with no success. I'm not sure where to put it. I think my main issue is getting exportImage() to be called more than once, since it's in the foreach loop i though it would be called on every scan, do you know why it's not ? the only way i can initiate a call again is to press button1. Thanks for your help Matt

          M Offline
          M Offline
          Marc Clifton
          wrote on last edited by
          #4

          You really don't want to use Thread.Sleep. You'll want to use the WinForm Timer class to set up a callback at a 5 second interval. The nice thing about the WinForm timer class is that you don't need to worry about marshalling to the application thread, since the event fires on the application thread. This means that you can update the UI, etc., without any worry about cross-threads. Marc

          Will work for food. Interacx

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups