none
colorFrame transfer on memory RRS feed

  • Question

  • Hi everyBody

    I working on WPF and Kinect SDK v1.

    For my application I need to convert colorFrame to byte[] and then transfer byte to memory (IntPtr).This is my code :

    byte[] pixels = new byte[colorFrame.PixelDataLength];
                    colorFrame.CopyPixelDataTo(pixels);

                     imageIntPr = Marshal.AllocHGlobal(pixels.Length);
                    Marshal.Copy(pixels, 0, imageIntPr, pixels.Length);

    After transferring and modify data by my application I need to remove imageIntPr from memory by :

    Marshal.FreeHGlobal(imageIntPr);

    but the problem is :when I want to remove data the system getting error:

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    dose anyone know how to solve problem?

    Is there any way to transfer colorFrame Directly to IntPtr without converting to a Byte Array?

    thanks


    ab.zaraki@gmail.com


    • Edited by AsusU31j Monday, March 26, 2012 2:47 PM
    Monday, March 26, 2012 2:44 PM

Answers

  • Hi
    I think the problem is that you don’t allocate the right imageIntPr size and when you write the data some of them are written in memory that is used but other applications/elements. Try this I think it will solve the problem.

    byte[] pixels = new byte[colorFrame.PixelDataLength];
                     colorFrame.CopyPixelDataTo(pixels);
    int size = Marshal.SizeOf(pixels [0]) * pixels.Length;
                     imageIntPr = Marshal.AllocHGlobal(size);
                     Marshal.Copy(pixels, 0, imageIntPr, pixels.Length);

    Nick

    • Marked as answer by AsusU31j Thursday, March 29, 2012 10:06 AM
    Monday, March 26, 2012 3:43 PM