void UpdateImage() { BinaryMap mask = Mask; if (IsVisible && mask != null) { int words = mask.WordWidth; int stride = words * BinaryMap.WordBytes; int height = mask.Height; byte[] pixels = new byte[height * stride]; for (int y = 0; y < height; ++y) { for (int xw = 0; xw < words; ++xw) { uint word = Calc.ReverseBitsInBytes(mask.GetWord(xw, y)); int wordAt = (height - 1 - y) * stride + xw * BinaryMap.WordBytes; for (int xb = 0; xb < BinaryMap.WordBytes; ++xb) { pixels[wordAt + xb] = (byte)(word >> (xb << 3)); } } } BitmapPalette palette = new BitmapPalette(new List <Color>() { ZeroColor, OneColor }); BitmapSource image = BitmapSource.Create(mask.Width, height, 96, 96, PixelFormats.Indexed1, palette, pixels, stride); SetValue(ImageProperty, image); } else { SetValue(ImageProperty, null); } }