I am using the Signature control in OpenNETCF. It works great for most everything I need.
However, I need a way invert the signature and load it back in.
It has a call to get the "bytes" for the signature (GetSignatureEx()
). It returns a byte[]
of the signature. This signature can then be loaded back in with LoadSignatureEx()
.
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.
If anyone out there knows a way to invert the signature and load it back in, I would be grateful to hear it.
Note for others who may care:
These bytes seem to have the following structure (in order):
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)
I will post my final code once I have it done.
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.
Just in case someone else wants it, here is my unfinished code. (I was close but the stuff to advance to the next "line" does not work quite right.) (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).)
But first, big thanks to MusiGenesis who helped me figure all this out. You are very helpful and I appreciate your efforts a lot!
Now the code:
private void InvertSignature(ref byte[] original)
{
int currentIndex = 0;
short width = BitConverter.ToInt16(original, 0);
short height = BitConverter.ToInt16(original, 2);
while (currentIndex < 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 < (nextNumberOfItems - 1); i += 4)
{
currentIndex = i;
//Invert Horizontal
int newHorzPoint = width - original[i] - 1;
if (newHorzPoint <= 0)
newHorzPoint = 0;
else if (newHorzPoint >= width - 1)
newHorzPoint = width - 1;
original[i] = (byte)newHorzPoint;
// Invert Vertical
int newVertPoint = height - original[i + 1] - 1;
if (newVertPoint <= 0)
newVertPoint = 0;
else if (newVertPoint >= height - 1)
newVertPoint = height - 1;
original[i + 1] = (byte)newVertPoint;
}
}
}