ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

CodeGo.net> OpenNETCF签名控制问题

2019-10-24 04:16:04  阅读:169  来源: 互联网

标签:compact-framework c net opennetcf


我在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).这似乎对我来说减少了出错的可能性.

万一有人想要它,这是我未完成的代码. (我很近,但是前进到下一个“行”的内容不太正确.)(编辑:我认为我更喜欢这种方式.我更新了下面的代码.它将一直有效因为Signature控件的宽度或高度不大于256.(请参阅下面的ctacke答案).

但是首先,非常感谢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;
        }
    }
}

解决方法:

完全未经测试的代码高尔夫:

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

或尝试使用此版本,假设前4个字节用于存储签名的宽度和高度(每个2个字节的短整数):

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

查看: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的答案,此操作的最后一枪(这适用于任何尺寸的签名):

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

标签:compact-framework,c,net,opennetcf
来源: https://codeday.me/bug/20191024/1918106.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有