none
How to take a still frame RRS feed

  • Question

  • I saw with the nerf gun mod that you can capture still frames, does anyone know the code to use?  Or where to find it?  I feel as if I looked all over but I may have overlooked something.  Thanks in advanced!
    Monday, June 20, 2011 6:59 PM

Answers

  • Helloy, Here's a code that you can use to capture a color image.
    private void Window_Loaded(object sender, EventArgs e)
    {
        nui = new Runtime();
    	nui.Initialize(RuntimeOptions.UseColor);
    	nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
    	nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_ColorFrameReady);
    }
    
    void nui_ColorFrameReady(object sender, ImageFrameReadyEventArgs e)
    {
    	// 32-bit per pixel, RGBA image
    	PlanarImage Image = e.ImageFrame.Image;
    	var capturedImage = BitmapSource.Create(
    		Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
    	// Save the capturedImage
    }
    
    Regards,
    Teemu Tapanila
    There's no place without shadow.
    Friday, June 24, 2011 5:20 PM
  •  

    you need a global variable:

    public int pictureValue = 0;

     

    then in that method:

    e.ImageFrame.ToBitmapSource().Save("capture" + pictureValue.ToString() + ".jpg", ImageFormat.Jpeg);

    pictureValue++;

     

    be careful. With this implementation, it will restart with "capture0.jpg" every time you restart the program. You'll have to read the filenames in the folder if you want the variable to start at the latest value.

    • Marked as answer by DARKSUPR3MACY Friday, June 24, 2011 6:58 PM
    Friday, June 24, 2011 6:50 PM
  • It's pretty simple actually.

     

    replace this:

    e.ImageFrame.ToBitmapSource().Save("capture" + pictureValue.ToString() + ".jpg", ImageFormat.Jpeg);

     

    with this:

    if(pictureValue < 50)

    {

    e.ImageFrame.ToBitmapSource().Save("capture" + pictureValue.ToString() + ".jpg", ImageFormat.Jpeg);

    }

     

    and change 50 to whatever maximum you want.

    • Marked as answer by DARKSUPR3MACY Friday, June 24, 2011 7:03 PM
    Friday, June 24, 2011 7:01 PM
  • Well the program I was working on is in C#, and the example code above is C#.  I think that would be the best way to go as most of the examples and help Microsoft gives is using C#
    • Marked as answer by DARKSUPR3MACY Monday, July 11, 2011 5:54 PM
    Monday, June 27, 2011 1:17 PM

All replies

  • Hoping someone can help me out this time, please
    Friday, June 24, 2011 3:45 PM
  • Helloy, Here's a code that you can use to capture a color image.
    private void Window_Loaded(object sender, EventArgs e)
    {
        nui = new Runtime();
    	nui.Initialize(RuntimeOptions.UseColor);
    	nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
    	nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_ColorFrameReady);
    }
    
    void nui_ColorFrameReady(object sender, ImageFrameReadyEventArgs e)
    {
    	// 32-bit per pixel, RGBA image
    	PlanarImage Image = e.ImageFrame.Image;
    	var capturedImage = BitmapSource.Create(
    		Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
    	// Save the capturedImage
    }
    
    Regards,
    Teemu Tapanila
    There's no place without shadow.
    Friday, June 24, 2011 5:20 PM
  • Thank you!  a sample code in the coding4fun toolkit a little while ago but I couldn't get it working.  By taking this line e.ImageFrame.ToBitmapSource().Save("capture.jpg", ImageFormat.Jpeg); and placing it at the end of what you provided, it worked! 

    One last question if you wouldn't mind, I remember coming across a code that I could have used a little while ago but forgot where it was...  How do you modify the code to have it save as capture.jpeg, capture_1.jpeg, capture_2.jpeg etc.. so it's not overwriting capture.jpeg each time?

    I know its going to be a loop of some sort and have it paste the current counter after capture(counter).jpeg, but not exactly sure how to set it up..
    Friday, June 24, 2011 6:00 PM
  •  

    you need a global variable:

    public int pictureValue = 0;

     

    then in that method:

    e.ImageFrame.ToBitmapSource().Save("capture" + pictureValue.ToString() + ".jpg", ImageFormat.Jpeg);

    pictureValue++;

     

    be careful. With this implementation, it will restart with "capture0.jpg" every time you restart the program. You'll have to read the filenames in the folder if you want the variable to start at the latest value.

    • Marked as answer by DARKSUPR3MACY Friday, June 24, 2011 6:58 PM
    Friday, June 24, 2011 6:50 PM
  • Thanks for the help once again!  Now I will have to get it to stop after a certain amount ahaha, but that's for a later time. 
    Friday, June 24, 2011 6:58 PM
  • It's pretty simple actually.

     

    replace this:

    e.ImageFrame.ToBitmapSource().Save("capture" + pictureValue.ToString() + ".jpg", ImageFormat.Jpeg);

     

    with this:

    if(pictureValue < 50)

    {

    e.ImageFrame.ToBitmapSource().Save("capture" + pictureValue.ToString() + ".jpg", ImageFormat.Jpeg);

    }

     

    and change 50 to whatever maximum you want.

    • Marked as answer by DARKSUPR3MACY Friday, June 24, 2011 7:03 PM
    Friday, June 24, 2011 7:01 PM
  • Well there we go!  I can't thank you enough for all your help!  As you can probably guess I'm not the best with programming haha..
    Friday, June 24, 2011 7:03 PM
  • No problem, gotta start somewhere right?
    Friday, June 24, 2011 7:12 PM
  • What type of code?

    VB, C#, C++ or F#?

     

    New to programing so this is basicly a trial & error process. (That & there is no videos to help)

     

    Help is apreatiated.

     

    Jordan

     

    PS I'm in year 8 if you read something that makes no sense. (Thinking about IPT next year)

    Sunday, June 26, 2011 7:43 AM
  • Well the program I was working on is in C#, and the example code above is C#.  I think that would be the best way to go as most of the examples and help Microsoft gives is using C#
    • Marked as answer by DARKSUPR3MACY Monday, July 11, 2011 5:54 PM
    Monday, June 27, 2011 1:17 PM