我正在使用 OpenNETCF 中的签名控件。它非常适合我需要的大多数东西。
但是,我需要一种方法反转签名并将其重新加载。
它有一个调用来获取签名的“字节”(GetSignatureEx()
)。它返回一个byte[]
的签名。然后可以使用以下命令重新加载此签名LoadSignatureEx()
.
我似乎无法弄清楚这些字节的系统。我以为它们可能是坐标,但现在看来并非如此。
如果有人知道一种反转签名并将其重新加载的方法,我将很高兴听到它。
其他可能关心的人请注意:
这些字节似乎具有以下结构(按顺序):
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)
完成后我将发布我的最终代码。
后期注意:
好吧,经过大量的工作,我发现使用内置的东西翻转视图是多么容易(感谢 MusiGenesis)。对我来说,这个过程似乎不太容易出错。
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).)
但首先,非常感谢 MusiGenesis 帮助我解决了这一切。您非常有帮助,我非常感谢您的努力!
现在的代码:
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;
}
}
}