[C#] Set TT_CameraFrameBuffer to picturebox

Post Reply
stanedav
Posts: 6
Joined: Wed Oct 26, 2011 2:49 am

[C#] Set TT_CameraFrameBuffer to picturebox

Post 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.
NaturalPoint - Brent
Posts: 59
Joined: Tue Nov 20, 2012 12:40 pm

Re: [C#] Set TT_CameraFrameBuffer to picturebox

Post 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
stanedav
Posts: 6
Joined: Wed Oct 26, 2011 2:49 am

Re: [C#] Set TT_CameraFrameBuffer to picturebox

Post by stanedav »

Hello Brent, thanks for answer. Did you find out something? Thanks
Post Reply