Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (ColorImageFrame colorframe = e.OpenColorImageFrame())
- {
- if (colorframe == null)
- {
- return;
- }
- byte[] pixels = new byte[colorframe.PixelDataLength];
- colorframe.CopyPixelDataTo(pixels);
- int stride = colorframe.Width * 4;//how many bytes we need (B G R empty)
- BitmapSource img = BitmapSource.Create(640, 480,
- 96, 96, PixelFormats.Bgr32, null, pixels, stride);
- var bitmapSource = colorframe.ToBitmapSource(); // using Coding4Fun.Kinect.Wpf extension
- Bitmap currentImage = KinectHelpers.GetBitmapFromBitmapSource(bitmapSource);
- Benchmark.Start();
- LockBitmap lockBitmap = new LockBitmap(currentImage);
- lockBitmap.LockBits();
- System.Drawing.Color compareClr = System.Drawing.Color.FromArgb(0, 0, 0, 255);
- for (int y = 0; y < lockBitmap.Height; y++)
- {
- for (int x = 0; x < lockBitmap.Width; x++)
- {
- if (lockBitmap.GetPixel(x, y) == compareClr)
- {
- lockBitmap.SetPixel(x, y, System.Drawing.Color.Red);
- }
- }
- }
- lockBitmap.UnlockBits();
- Benchmark.End();
- double seconds = Benchmark.GetSeconds();
- Image1.Source = img;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement