Browse Source

Implemented getColorImage and ColorImage and added Demo.

Daniel Kauth 11 years ago
parent
commit
1a058c2a8f

+ 40 - 0
bbiwarg/DataSource/ColorImage.cs

@@ -8,5 +8,45 @@ namespace bbiwarg.DataSource
 {
     class ColorImage
     {
+        private int width, height;
+        private byte[] data;
+
+        public ColorImage(int width, int height, byte[] data)
+        {
+            this.width = width;
+            this.height = height;
+            this.data = data;
+        }
+
+        public int getWidth()
+        {
+            return width;
+        }
+
+        public int getHeight()
+        {
+            return height;
+        }
+
+        public byte getR(int x, int y)
+        {
+            return data[4 * (y * width + x) + 0];
+        }
+
+        public byte getG(int x, int y)
+        {
+            return data[4 * (y * width + x) + 1];
+        }
+
+        public byte getB(int x, int y)
+        {
+            return data[4 * (y * width + x) + 2];
+        }
+
+        public byte getA(int x, int y)
+        {
+            return data[4 * (y * width + x) + 3];
+        }
+
     }
 }

+ 6 - 3
bbiwarg/DataSource/IisuDataSource.cs

@@ -139,14 +139,17 @@ namespace bbiwarg.DataSource
 
         public ColorImage getColorImage()
         {
-            Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
+            Iisu.Data.IImageInfos imageInfos = colorImage.Value.ImageInfos;
             int width = (int)imageInfos.Width;
             int height = (int)imageInfos.Height;
             int numBytes = (int)imageInfos.BytesRaw;
 
-            Console.WriteLine("width: " + width + " height: " + height + " numBytes: " + numBytes);
+            IntPtr imageData = colorImage.Value.Raw;
+
+            byte[] colorData = new byte[numBytes];
+            Marshal.Copy(imageData, colorData, 0, numBytes);
 
-            return new ColorImage();
+            return new ColorImage(width, height, colorData);
         }
 
         private void checkHandIndex(uint handIndex) 

+ 3 - 4
bbiwarg/Test/TestDataSource.cs

@@ -25,18 +25,17 @@ namespace bbiwarg.Test
                 {
                     ColorImage image = source.getColorImage();
 
-                    /*Bitmap bm = new Bitmap(image.getWidth(), image.getHeight());
+                    Bitmap bm = new Bitmap(image.getWidth(), image.getHeight());
                     for (int x = 0; x < image.getWidth(); ++x)
                     {
                         for (int y = 0; y < image.getHeight(); ++y) 
                         {
-                            int value = (int) (image.getDepth(x, y) / 1000.0 * 255.0) % 256;
-                            bm.SetPixel(x, y, Color.FromArgb(255, value, value, value));
+                            bm.SetPixel(x, y, Color.FromArgb(image.getA(x, y), image.getR(x, y), image.getG(x, y), image.getB(x, y)));
                         }
                     }
 
                     bm.Save("test." + j + ".png");
-                    j++;*/
+                    j++;
                 }
 
                 source.releaseFrame();

+ 1 - 1
bbiwarg/bbiwarg.csproj

@@ -32,7 +32,7 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <PropertyGroup>
-    <StartupObject>Test.bbiwarg.TestDataSource</StartupObject>
+    <StartupObject>bbiwarg.Test.TestDataSource</StartupObject>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="iisuNet, Version=3.0.0.0, Culture=neutral, processorArchitecture=x86">