Page 1 of 1

[C#] Set TT_CameraFrameBuffer to picturebox

Posted: Sat Apr 06, 2013 4:04 am
by stanedav
Hello, I am trying to display camera buffer in my application. I am using TT_CameraFrameBuffer (with V120Trio and NPTrackingTools.dll)function with this code after TT_Update() :

Code: Select all

GCHandle gc = GCHandle.Alloc(new byte[320 * 240], GCHandleType.Pinned);
public Bitmap bmp = new Bitmap(320, 240, PixelFormat.Format8bppIndexed);


gc.Free();
gc = GCHandle.Alloc(new byte[320 * 240], GCHandleType.Pinned);
bool a = TT_CameraFrameBuffer(0, 320, 240, 0, 8, gc.AddrOfPinnedObject());

byte[] b = (byte[])gc.Target;

BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, 320, 240), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

// IntPtr ptr = gc.AddrOfPinnedObject();
Marshal.Copy(b, 0, bmpData.Scan0, 320 * 240);
bmp.UnlockBits(bmpData);
Then i put it in classic winform picturebox like:

Code: Select all

PictureBox.Image = cam.bmp;
PictureBox.Invalidate();
It goes approximately five seconds in crazy colors like this:
http://i.imgur.com/emmiKaj.png
and then it falls with this exception:
Object is currently in use elsewhere.

I think that mistake will be somewhere in PixelFormat. Am I right? Please help me how to display camera buffer in appliaction properly.
Thanks for your help
D.

Re: [C#] Set TT_CameraFrameBuffer to picturebox

Posted: Wed Apr 10, 2013 8:01 am
by NaturalPoint - Brent
Hi Stanedav,
I will see if I can get an answer for you on your question. Thank you for your patience while I look into this.

Brent Mason

Re: [C#] Set TT_CameraFrameBuffer to picturebox

Posted: Tue Apr 16, 2013 12:46 am
by stanedav
Hello Brent, thanks for answer. Did you find out something? Thanks