Advertisement
Guest User

WFP

a guest
Feb 24th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using (ColorImageFrame colorframe = e.OpenColorImageFrame())
  2.             {
  3.  
  4.  
  5.                 if (colorframe == null)
  6.                 {
  7.                     return;
  8.                 }
  9.          
  10.                 byte[] pixels = new byte[colorframe.PixelDataLength];
  11.                 colorframe.CopyPixelDataTo(pixels);
  12.  
  13.                 int stride = colorframe.Width * 4;//how many bytes we need (B G R empty)
  14.                 BitmapSource img = BitmapSource.Create(640, 480,
  15.                     96, 96, PixelFormats.Bgr32, null, pixels, stride);
  16.  
  17.                 var bitmapSource = colorframe.ToBitmapSource(); // using Coding4Fun.Kinect.Wpf extension
  18.                 Bitmap currentImage = KinectHelpers.GetBitmapFromBitmapSource(bitmapSource);
  19.  
  20.                 Benchmark.Start();
  21.                 LockBitmap lockBitmap = new LockBitmap(currentImage);
  22.                 lockBitmap.LockBits();
  23.  
  24.                 System.Drawing.Color compareClr = System.Drawing.Color.FromArgb(0, 0, 0, 255);
  25.                 for (int y = 0; y < lockBitmap.Height; y++)
  26.                 {
  27.                     for (int x = 0; x < lockBitmap.Width; x++)
  28.                     {
  29.                         if (lockBitmap.GetPixel(x, y) == compareClr)
  30.                         {
  31.                             lockBitmap.SetPixel(x, y, System.Drawing.Color.Red);
  32.                         }
  33.                     }
  34.                 }
  35.                 lockBitmap.UnlockBits();
  36.                 Benchmark.End();
  37.                 double seconds = Benchmark.GetSeconds();
  38.                 Image1.Source = img;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement