title: OpenNETCF Signature control question
body: <p>I am using the Signature control in OpenNETCF.  It works great for most everything I need.</p>
  
  <p>However, I need a way invert the signature and load it back in.</p>
  
  <p>It has a call to get the "bytes" for the signature (<code>GetSignatureEx()</code>).  It returns a <code>byte[]</code> of the signature.  This signature can then be loaded back in with <code>LoadSignatureEx()</code>.</p>
  
  <p>I can't seem to figure out the system for these bytes.  I thought they may be coordinates, but it does not seem so now.</p>
  
  <p>If anyone out there knows a way to invert the signature and load it back in, I would be grateful to hear it.</p>
  
  <hr>
  
  <p>Note for others who may care:</p>
  
  <p>These bytes seem to have the following structure (in order):</p>
  
  <pre>2 bytes to show Width  
  2 bytes to show Height  
    -- This next part repeats till the end of the array  
    2 bytes to show How many points are in the next line  
      -- This next part repeats as many times as the previous line indicated  
      1 byte for the x coordinate of the point  
      1 byte for the y coordinate of the point  
      2 bytes for the width of the pen (I am not 100% sure on this one)  </pre>
  
  <p>I will post my final code once I have it done.</p>
  
  <hr>
  
  <p>Later Note:
  Ok after tons of work, I found how easy it is to flip the view using the built in stuff (thanks MusiGenesis).  That seems to be way less error prone a process to me.</p>
  
  <p><del>Just in case someone else wants it, here is my <strong>unfinished</strong> code.  (I was close but the stuff to advance to the next "line" does not work quite right.)</del>  (EDIT: I decided that I liked the way this worked a bit more.  I have updated the code below.  It will work as long as the width or height of the Signature control is not greater than 256.  (See ctacke's answer below).)</p>
  
  <p>But first, big thanks to MusiGenesis who helped me figure all this out.  You are very helpful and I appreciate your efforts a lot!</p>
  
  <p>Now the code:  </p>
  
  <pre><code>private void InvertSignature(ref byte[] original)
  {
      int currentIndex = 0;
      short width = BitConverter.ToInt16(original, 0);
      short height = BitConverter.ToInt16(original, 2);
      while (currentIndex &lt; original.Length - 4)
      {
          // Move past the last iteration (or the width and hight for the first time through).
          currentIndex += 4;
          // Find the length of the next segment.
          short nextGroup = BitConverter.ToInt16(original, currentIndex);
          //Advance one so we get past the 2 byte group
          currentIndex += 2;
          // Find the actual index of the last set of coordinates for this segment.
          int nextNumberOfItems = ((nextGroup) * 4) + currentIndex;
          // Invert the coordinates
          for (int i = currentIndex; i &lt; (nextNumberOfItems - 1); i += 4)
          {
              currentIndex = i;
  
              //Invert Horizontal
              int newHorzPoint = width - original[i] - 1;
              if (newHorzPoint &lt;= 0)
                  newHorzPoint = 0;
              else if (newHorzPoint &gt;= width - 1)
                  newHorzPoint = width - 1;
              original[i] = (byte)newHorzPoint;
  
              // Invert Vertical
              int newVertPoint = height - original[i + 1] - 1;
              if (newVertPoint &lt;= 0)
                  newVertPoint = 0;
              else if (newVertPoint &gt;= height - 1)
                  newVertPoint = height - 1;
              original[i + 1] = (byte)newVertPoint;
          }
      }
  }
  </code></pre>