Question

I'm looking at the colors basic sample from the Kinect developers toolkit

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit;
using Microsoft.Kinect.Toolkit.Controls;


namespace BrianColorViewer
{
    public partial class MainWindow : Window
    {
        KinectSensor sensor;
        WriteableBitmap colorBitmap;
        byte[] colorPixels;

        public MainWindow()
        {
            InitializeComponent();            
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (var potential in KinectSensor.KinectSensors)
            {
                if (potential.Status == KinectStatus.Connected)
                {
                    sensor = potential;
                    break;
                }
            }

            if (null != sensor)
            {
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution1280x960Fps12);
                colorPixels = new byte[sensor.ColorStream.FramePixelDataLength];
                colorBitmap = new WriteableBitmap(sensor.ColorStream.FrameWidth,     sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                Image.Source = colorBitmap;
                sensor.ColorFrameReady += sensor_ColorFrameReady;

and trying to fully understand the WriteableBitmap feature. According to MSDN (http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28v=vs.110%29.aspx) the inputs for a WriteableBitmap are pixelWidth: The desired width of the bitmap. pixelHeight:The desired height of the bitmap. dpiX: The horizontal dots per inch (dpi) of the bitmap. dpiY: The vertical dots per inch (dpi) of the bitmap. pixelFormat: The System.Windows.Media.PixelFormat of the bitmap. palette: The System.Windows.Media.Imaging.BitmapPalette of the bitmap.

In the sample code I understand pixel width and height, however I don't know how dpiX and dpiY were generated. Additionally I don't understand the call to PixelFormats.Bgr32 or the null variable assigned to the palette parameter.

The reason for my interest in WriteableBitmaps is that I'm wondering if you can save 2 and compare them to each other to see how different two images are. Therefore, I'm trying to fully understand them. Thanks!

Was it helpful?

Solution

A WriteableBitmap can be used to write new bytes in order to update the UI. This enables us to use the same WriteableBitmap and use the same resources in memory but only update the content.

In my tutorial I explain how you can use it in a Kinect scenario!

OTHER TIPS

The dpi is dots per inch, often used for resolution. The pixel format is format that is used for pixel coloring (rbg, grayscale, argb). The color palette is null so it resorts to the default color palette. Know you can use encoders to save writable bitmaps and you can compare them manually or with other APIs(eg. EmguCV).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top