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);
Code: Select all
PictureBox.Image = cam.bmp;
PictureBox.Invalidate();
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.