Trying to capture a JPG and upload to a server w/out saving to disk. RRS feed

  • Question

  • Hey guys,  I'm building my first official Kinect app (built one using the beta SDK) and I'm running into a problem.  I'm trying to simply upload an image to a server from the Kinect camera.  Here's the code I'm using:

    void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                        if (colorFrame == null)
                        byte[] pixels;
                        using (MemoryStream jpg_img = new MemoryStream())
                            BitmapFromSource(colorFrame.ToBitmapSource()).Save(jpg_img, System.Drawing.Imaging.ImageFormat.Jpeg);
                            pixels = jpg_img.ToArray();
                        //Code to upload to the server goes here.

    The problem is that every time I try to call that Save function to save it into the MemoryStream, a general GDI+ error is thrown.  Anyone know how to get around this?

    Friday, April 27, 2012 2:13 AM

All replies

  • Anyone have any ideas here?  This has to be a pretty common request.
    Friday, April 27, 2012 11:26 PM
  • Hi Chris,

    I am using the following code:

    void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
                using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                    if (colorFrame != null)
                        //Using standard SDK
                        this.colorPixelData = new byte[colorFrame.PixelDataLength];
                        this.outputImage = new WriteableBitmap(
                        96,  // DpiX
                        96,  // DpiY
                        new Int32Rect(0, 0, colorFrame.Width, colorFrame.Height),
                        colorFrame.Width * 4,
                        image1.Source = this.outputImage;
                        //Using Coding4Fun Kinect Toolkit
                        //kinectColorImage.Source = imageFrame.ToBitmapSource();
    I don't remember where i found this, but i think it was an MSDN page.
    Monday, April 30, 2012 7:59 AM