Esempio n. 1
0
        //Update the display parameters based on the image description
        void imager_DescriptionReceived(object sender, DescriptionReceivedEventArgs e)
        {
            imager.UnbindChannels(); //Unbind the channels so we can set the new channel bindings base on the new description

            //Save the size of the image to class variables so we can use it later
            width  = e.Columns;
            height = e.Rows;
            depth  = e.Depth;

            //Setup the colors
            if (imager.Channels.Length == 1)
            {
                //Grayscale doesn't require channel binding
                if (imager.Channels[0].BitDepth == ImageBitDepth.unsigned8bit)
                {
                    imageFormat     = PixelFormats.Gray8;
                    bytesPerPixel   = 1;
                    bytesPerChannel = 1;
                }
                else if (imager.Channels[0].BitDepth == ImageBitDepth.float32bit)
                {
                    imageFormat     = PixelFormats.Gray32Float;
                    bytesPerPixel   = 4;
                    bytesPerChannel = 4;
                }
                else
                {
                    imageFormat     = PixelFormats.Gray16;
                    bytesPerPixel   = 2;
                    bytesPerChannel = 2;
                }
            }
            else if (imager.Channels.Length == 3)
            {
                //For RGB, we will bind the first 3 channels
                //In a real application, it would be preferable to bind by channel name
                if (imager.Channels[0].BitDepth == ImageBitDepth.unsigned8bit)
                {
                    imageFormat     = PixelFormats.Rgb24;
                    bytesPerPixel   = 3;
                    bytesPerChannel = 1;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 1, imager.Channels[2].Name, 2);
                    }
                }
                else if (imager.Channels[0].BitDepth == ImageBitDepth.float32bit)
                {
                    //WPF doesn't support a 96 bits-per-pixel RGB format
                    throw new Exception("Format not supported.");
                }
                else
                {
                    imageFormat     = PixelFormats.Rgb48;
                    bytesPerPixel   = 6;
                    bytesPerChannel = 2;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 2, imager.Channels[2].Name, 4);
                    }
                }
            }
            else if (imager.Channels.Length == 4)
            {
                //Similiarly, for RGBA we will bind the first 4 channels
                //In a real application, it would be preferable to bind by channel name
                if (imager.Channels[0].BitDepth == ImageBitDepth.unsigned8bit)
                {
                    //Since this format is bgra instead of rgba, we reverse the order of the channels assuming blue will be the 3rd channel and red the 1st
                    imageFormat     = PixelFormats.Bgra32;
                    bytesPerPixel   = 4;
                    bytesPerChannel = 1;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[2].Name, 0, imager.Channels[1].Name, 1, imager.Channels[0].Name, 2, imager.Channels[3].Name, 3);
                    }
                }
                else if (imager.Channels[0].BitDepth == ImageBitDepth.float32bit)
                {
                    imageFormat     = PixelFormats.Rgba128Float;
                    bytesPerPixel   = 16;
                    bytesPerChannel = 4;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 4, imager.Channels[2].Name, 8, imager.Channels[3].Name, 12);
                    }
                }
                else
                {
                    imageFormat     = PixelFormats.Rgba64;
                    bytesPerPixel   = 8;
                    bytesPerChannel = 2;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 2, imager.Channels[2].Name, 4, imager.Channels[3].Name, 6);
                    }
                }
            }

            if (bytesPerPixel != 0)
            {
                image = new WriteableBitmap(width, height, 96.0, 96.0, imageFormat, null);
                DisplayedImage.Source = image;
                rawImage = new byte[e.Rows * e.Columns * e.Depth * bytesPerPixel];

                ConsoleTextBox.Text += String.Format("New description Received at: {0}, the new size is {1} x {2} x {3} with a format of " + imageFormat.ToString() + "\r\n", e.Time, e.Rows, e.Columns, e.Depth);
            }
        }
Esempio n. 2
0
        //Update the display parameters based on the image description
        void imager_DescriptionReceived(object sender, DescriptionReceivedEventArgs e)
        {
            imager.UnbindChannels(); //Unbind the channels so we can set the new channel bindings base on the new description

            //Save the size of the image to class variables so we can use it later
            width = e.Columns;
            height = e.Rows;
            depth = e.Depth;

            //Setup the colors
            if (imager.Channels.Length == 1)
            {
                //Grayscale doesn't require channel binding
                if (imager.Channels[0].BitDepth == ImageBitDepth.unsigned8bit)
                {
                    imageFormat = PixelFormats.Gray8;
                    bytesPerPixel = 1;
                    bytesPerChannel = 1;
                }
                else if (imager.Channels[0].BitDepth == ImageBitDepth.float32bit)
                {
                    imageFormat = PixelFormats.Gray32Float;
                    bytesPerPixel = 4;
                    bytesPerChannel = 4;
                }
                else
                {
                    imageFormat = PixelFormats.Gray16;
                    bytesPerPixel = 2;
                    bytesPerChannel = 2;
                }
            }
            else if (imager.Channels.Length == 3)
            {
                //For RGB, we will bind the first 3 channels
                //In a real application, it would be preferable to bind by channel name
                if (imager.Channels[0].BitDepth == ImageBitDepth.unsigned8bit)
                {
                    imageFormat = PixelFormats.Rgb24;
                    bytesPerPixel = 3;
                    bytesPerChannel = 1;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 1, imager.Channels[2].Name, 2);
                    }
                }
                else if (imager.Channels[0].BitDepth == ImageBitDepth.float32bit)
                {
                    //WPF doesn't support a 96 bits-per-pixel RGB format
                    throw new Exception("Format not supported.");
                }
                else
                {
                    imageFormat = PixelFormats.Rgb48;
                    bytesPerPixel = 6;
                    bytesPerChannel = 2;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 2, imager.Channels[2].Name, 4);
                    }
                }
            }
            else if (imager.Channels.Length == 4)
            {
                //Similiarly, for RGBA we will bind the first 4 channels
                //In a real application, it would be preferable to bind by channel name
                if (imager.Channels[0].BitDepth == ImageBitDepth.unsigned8bit)
                {
                    //Since this format is bgra instead of rgba, we reverse the order of the channels assuming blue will be the 3rd channel and red the 1st
                    imageFormat = PixelFormats.Bgra32;
                    bytesPerPixel = 4;
                    bytesPerChannel = 1;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[2].Name, 0, imager.Channels[1].Name, 1, imager.Channels[0].Name, 2, imager.Channels[3].Name, 3);
                    }
                }
                else if (imager.Channels[0].BitDepth == ImageBitDepth.float32bit)
                {
                    imageFormat = PixelFormats.Rgba128Float;
                    bytesPerPixel = 16;
                    bytesPerChannel = 4;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 4, imager.Channels[2].Name, 8, imager.Channels[3].Name, 12);
                    }
                }
                else
                {
                    imageFormat = PixelFormats.Rgba64;
                    bytesPerPixel = 8;
                    bytesPerChannel = 2;
                    if (useChannelBinding)
                    {
                        imager.BindChannels("BoundVirtualChannel", imager.Channels[0].Name, 0, imager.Channels[1].Name, 2, imager.Channels[2].Name, 4, imager.Channels[3].Name, 6);
                    }
                }
            }

            if (bytesPerPixel != 0)
            {
                image = new WriteableBitmap(width, height, 96.0, 96.0, imageFormat, null);
                DisplayedImage.Source = image;
                rawImage = new byte[e.Rows * e.Columns * e.Depth * bytesPerPixel];

                ConsoleTextBox.Text += String.Format("New description Received at: {0}, the new size is {1} x {2} x {3} with a format of " + imageFormat.ToString() + "\r\n", e.Time, e.Rows, e.Columns, e.Depth);
            }
        }