title: ColorMap values WPF
body: <p>I'm working with VS C# 2010 and I'm creating a WPF application. I have to represent a matrix with different values, and to make them a bit easier to understand I'd like to use a ColorMap bar. I did create once a project in Windows Forms (it has System.Drawings but WPF doesn't). Is there any way of creating it or adapting it by creating my own "library"?</p>
  
  <p>Here is an example of what I'd like to do:
  <a href="https://i.stack.imgur.com/q8hjS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q8hjS.png" alt="Example"></a></p>
  
  <p>But furthermore I'd like to set the ranges on the bar as well. If it helps, here is the code using ColorMap in Windows Forms (it does not work in WPF):</p>
  
  <pre><code>namespace Example1_8
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
              SetStyle(ControlStyles.ResizeRedraw, true);
              this.BackColor = Color.White;
              this.Width = 340;
              this.Height = 340;
          }
  
          protected override void OnPaint(PaintEventArgs e)
          {
              Graphics g = e.Graphics;
  
              int width = 30;
              int height = 128;
              int y = 0;
              // Create opaque color maps with alpha = 255:
              ColorMap cm = new ColorMap();
              DrawColorBar(g, 10 + 4 * 40, y, width, height, cm, "Jet");
              }
  
          private void DrawColorBar(Graphics g, int x, int y, int width, int height, 
              ColorMap map, string str)
          {
              int[,] cmap = new int[64, 4];
              switch (str)
              {
                  case "Jet":
                      cmap = map.Jet();
                      break;
              }
  
              int ymin = 0;
              int ymax = 32;
              int dy = height / (ymax - ymin);
              int m = 64;
              for (int i = 0; i &lt; 32; i++)
              {
                  int colorIndex = (int)((i - ymin) * m / (ymax - ymin));
                  SolidBrush aBrush = new SolidBrush(Color.FromArgb(
                      cmap[colorIndex, 0], cmap[colorIndex, 1],
                      cmap[colorIndex, 2], cmap[colorIndex, 3]));
                  g.FillRectangle(aBrush, x, y + i * dy, width, dy);
              }
          }
      }
  }
  </code></pre>