OpenNETCF签名控制问题 [英] OpenNETCF Signature control question

查看:168
本文介绍了OpenNETCF签名控制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenNETCF签名控件。这对于大多数我需要的一切的伟大工程。

不过,我需要一种方法颠倒签名并加载回。

它有一个调用来获取字节的签名( GetSignatureEx())。它返回一个签名的byte [] 。这个签名就可以装回与 LoadSignatureEx()

我似乎无法找出系统的这些字节。我想他们可能是坐标,但它似乎不那么现在。

如果有任何人知道的方式来颠倒签名并加载回来,我将不胜感激听到它。


请注意别人谁可以照顾:

这些字节似乎具有以下结构(按顺序):

 2个字节,显示宽度
2个字节来显示高度
   - 下一部分重复,直到阵列的端部
  2个字节显示有多少点是下一行
     - 下一部分重复多次指出的previous线
    点的1个字节为x坐标
    点的1个字节的y坐标
    2个字节为笔的宽度(我不是100%肯定在这一个)

我会后我的最后code,一旦我把它完成。


后来注意: 好吧吨的工作之后,我发现它是多么容易翻转使用内置的东西(感谢MusiGenesis)的观点。这似乎是这样不容易出错的方法给我。

万一有人需要它,这是我的未完成的 code。 (我很接近,但东西前进到下一个行不工作完全正确。)(编辑:我决定,我很喜欢这个工作多一点的方式,我已经更新了code下面,它会一直工作作为签名控件的宽度或高度不大于256更大(见下文ctacke的答案)。)

但首先,非常感谢MusiGenesis谁帮我计算出这一切。你是非常有益的,我AP preciate你的努力了很多!

现在的code:

 私人无效InvertSignature(参考byte []的原)
{
    INT CURRENTINDEX = 0;
    短宽度= BitConverter.ToInt16(原始,0);
    身材矮小= BitConverter.ToInt16(原件,2);
    而(CURRENTINDEX< original.Length  -  4)
    {
        //(通过或宽和高第一次)把过去的最后一次迭代。
        CURRENTINDEX + = 4;
        //找到下一个段的长度。
        短nextGroup = BitConverter.ToInt16(原件,CURRENTINDEX);
        //进展之一,所以我们让过去的2个字节组
        CURRENTINDEX + = 2;
        //找到最后一组坐标,该段的实际指标。
        INT nextNumberOfItems =((nextGroup)* 4)+ CURRENTINDEX;
        //倒置坐标
        对于(INT I = CURRENTINDEX;我≤(nextNumberOfItems  -  1); I + = 4)
        {
            CURRENTINDEX =我;

            //反转水平
            INT newHorzPoint =宽度 -  [i]原 -  1;
            如果(newHorzPoint&所述; = 0)
                newHorzPoint = 0;
            否则,如果(newHorzPoint> =宽度 -  1)
                newHorzPoint =宽度 -  1;
            [i]原=(字节)newHorzPoint;

            //反转垂直
            INT newVertPoint =身高 - 原[I + 1]  -  1;
            如果(newVertPoint&所述; = 0)
                newVertPoint = 0;
            否则,如果(newVertPoint> =身高 -  1)
                newVertPoint =身高 -  1;
            原来的[I + 1] =(字节)newVertPoint;
        }
    }
}
 

解决方案

完全-untested- code高尔夫:

 公共无效InvertSignature(参考byte []的原,
    布尔invertHorizo​​ntal,布尔invertVertical)
{
    的for(int i = 0; I< original.Length;我+ = 2)
    {
        如果((原始[I] = 0)及!及(原始[I + 1] = 0)!)
        {
            如果(invertHorizo​​ntal)
            {
                [i]原= 232  -  [i]原 -  1;
            }
            如果(invertVertical)
            {
                原来的[I + 1] = 64  - 原来的[I + 1]  -  1;
            }
        }
    }
}
 

或者尝试这个版本中,在假设前4个字节被用于存储所述签名(2字节短整型每个)的宽度和高度:

 公共无效InvertSignature(参考byte []的原,
    布尔invertHorizo​​ntal,布尔invertVertical)
{
    字节W =(字节)BitConverter.ToInt16(原件,0) -  1;
    字节H =(字节)BitConverter.ToInt16(原件,2) -  1;
    //做:炸毁当w或h是> 255
    的for(int i = 4; I< original.Length;我+ = 2)
    {
        如果((原始[I] = 0)及!及(原始[I + 1] = 0)!)
        {
            如果(invertHorizo​​ntal)
            {
                [i]原= W  -​​  [i]原;
            }
            如果(invertVertical)
            {
                原来的[I + 1] = H  - 原[I + 1];
            }
        }
    }
}
 

请参阅:<一href="http://stackoverflow.com/questions/812125/converting-opennetcf-getsignatureex-to-bitmap-on-desktop">http://stackoverflow.com/questions/812125/converting-opennetcf-getsignatureex-to-bitmap-on-desktop

更新:鉴于你的,为什么你需要反转的签名,可能更容易让你刚(后顾客的迹象,然后回)反转设备的ScreenOrientation 180度的说明。通过这种方式,你也可以有告诉他们签署什么,客户的标签 - 否则他们会在看一堆颠倒的东西(除了签名控件本身等)

要做到这一点,添加引用 Microsoft.WindowsCE.Forms 到您的项目,然后添加使用Microsoft.WindowsCE.Forms; 到文件的顶部。

要180度翻转屏幕:

  SystemSettings.ScreenOrientation = ScreenOrientation.Angle180;
 

要设置恢复正​​常:

  SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
 

如果你在模拟器中运行,你的屏幕仍然会出现正常直立,但皮肤被翻转倒置。

更新:最后一次在此拍摄,根据 ctacke 的回答(这应该适用于任何尺寸的签名):

 公共无效InvertSignature(参考byte []的原,
    布尔invertHorizo​​ntal,布尔invertVertical)
{
    总之W = BitConverter.ToInt16(原件,0);
    总之H = BitConverter.ToInt16(原件,2);
    INT I = 4;
    而(I&LT; original.Length)
    {
        如果(invertHorizo​​ntal)
        {
            如果(瓦特&所述; 256)
            {
                如果([i]原!= 0)
                {
                    [i]原=(字节)W  -  [i]原 -  1;
                }
                我++;
            }
            其他
            {
                短VAL = BitConverter.ToInt16(原件,I);
                如果(VAL!= 0)
                {
                    VAL = W  -​​  VAL  -  1;
                    byte []的valbytes = BitConverter.GetBytes(VAL);
                    Buffer.BlockCopy(valbytes,0,原来,我,2);
                }
                I + = 2;
            }
        }
        其他
        {
            I + =(W&LT; 256)? 1:2;
        }
        如果(invertVertical)
        {
            如果(H&所述; 256)
            {
                如果([i]原!= 0)
                {
                    [i]原=(字节)H  -  [i]原 -  1;
                }
                我++;
            }
            其他
            {
                短VAL = BitConverter.ToInt16(原件,I);
                如果(VAL!= 0)
                {
                    VAL = H  -  VAL  -  1;
                    byte []的valbytes = BitConverter.GetBytes(VAL);
                    Buffer.BlockCopy(valbytes,0,原来,我,2);
                }
                I + = 2;
            }
        }
        其他
        {
            I + =(H&LT; 256)? 1:2;
        }
    }
}
 

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;
        }
    }
}

解决方案

Completely-untested-code Golf:

public void InvertSignature(ref byte[] original, 
    bool invertHorizontal, bool invertVertical)
{
    for (int i = 0; i < original.Length; i += 2)
    {
        if ((original[i] != 0) && (original[i + 1] != 0))
        {
            if (invertHorizontal)
            {
                original[i] = 232 - original[i] - 1;
            }
            if (invertVertical)
            {
                original[i + 1] = 64 - original[i + 1] - 1;
            }
        }
    }
}

Or try this version, on the assumption that the first 4 bytes are used to store the width and height of the signature (2 byte short ints for each):

public void InvertSignature(ref byte[] original, 
    bool invertHorizontal, bool invertVertical)
{
    byte w = (byte)BitConverter.ToInt16(original, 0) - 1;
    byte h = (byte)BitConverter.ToInt16(original, 2) - 1;
    // TO DO: blow up if w or h are > 255
    for (int i = 4; i < original.Length; i += 2)
    {
        if ((original[i] != 0) && (original[i + 1] != 0))
        {
            if (invertHorizontal)
            {
                original[i] = w - original[i];
            }
            if (invertVertical)
            {
                original[i + 1] = h - original[i + 1];
            }
        }
    }
}

See: http://stackoverflow.com/questions/812125/converting-opennetcf-getsignatureex-to-bitmap-on-desktop

Update: Given your description of why you need to invert the signature, it might be easier for you to just invert the ScreenOrientation of your device by 180 degrees (and then back after the customer signs). This way you could also have labels that tell the customer what they're signing - otherwise they're going to be looking at a bunch of upside-down stuff (other than the signature control itself).

To do this, add a reference to Microsoft.WindowsCE.Forms to your project, then add using Microsoft.WindowsCE.Forms; to the top of your file.

To invert the screen by 180 degrees:

SystemSettings.ScreenOrientation = ScreenOrientation.Angle180;

To set back to normal:

SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;

If you're running this in the emulator, your screen will still appear normally upright, but the skin gets flipped upside-down.

Update: one last shot at this, based on ctacke's answer (this should work for signatures with any dimensions):

public void InvertSignature(ref byte[] original, 
    bool invertHorizontal, bool invertVertical)
{
    short w = BitConverter.ToInt16(original, 0);
    short h = BitConverter.ToInt16(original, 2);
    int i = 4;
    while (i < original.Length)
    {
        if (invertHorizontal)
        {
            if (w < 256)
            {
                if (original[i] != 0)
                {
                    original[i] = (byte)w - original[i] - 1;
                }
                i++;
            }
            else
            {
                short val = BitConverter.ToInt16(original, i);
                if (val != 0)
                {
                    val = w - val - 1;
                    byte[] valbytes = BitConverter.GetBytes(val);
                    Buffer.BlockCopy(valbytes, 0, original, i, 2);
                }
                i += 2;
            }
        }
        else
        {
            i += (w < 256) ? 1 : 2;
        }
        if (invertVertical)
        {
            if (h < 256)
            {
                if (original[i] != 0)
                {
                    original[i] = (byte)h - original[i] - 1;
                }
                i++;
            }
            else
            {
                short val = BitConverter.ToInt16(original, i);
                if (val != 0)
                {
                    val = h - val - 1;
                    byte[] valbytes = BitConverter.GetBytes(val);
                    Buffer.BlockCopy(valbytes, 0, original, i, 2);
                }
                i += 2;
            }
        }
        else
        {
            i += (h < 256) ? 1 : 2;
        }
    }
}

这篇关于OpenNETCF签名控制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆