0

我正在绘制如下所示的签名并获取 XY 坐标并将其保存到数组列表中。

Bitmap bmp;

        //Graphics object 
        Graphics graphics;

        //Pen object
        Pen pen = new Pen(Color.Black);

        // Array List of line segments
        ArrayList pVector = new ArrayList();

        //Point object
        Point lastPoint = new Point(0, 0);

 protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            // process if currently drawing signature
            if (!drawSign)
            {
                // start collecting points
                drawSign = true;

                // use current mouse click as the first point
                lastPoint.X = e.X;
                lastPoint.Y = e.Y;
            }

        }

 protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            // process if drawing signature
            if (drawSign)
            {
                if (graphics != null)
                {
                    // draw the new segment on the memory bitmap
                    graphics.DrawLine(pen, lastPoint.X, lastPoint.Y, e.X, e.Y);
                    pVector.Add(lastPoint.X + " " + lastPoint.Y + " " + e.X + " " + e.Y);

                    // update the current position
                    lastPoint.X = e.X;
                    lastPoint.Y = e.Y;

                    // display the updated bitmap
                    Invalidate();
                }
            }
        }

使用 arrylist (pVector) 我将值作为字符串 (singature) 和图像保存到数据库中,如下所示

//Saving value to Database
ArrayList arrSign = new ArrayList();
                arrSign = this.signatureControl.getPVector();

                string singature = "";

                for (int i = 0; i < arrSign.Count; i++)
                {
                    singature = singature + arrSign[i].ToString() + "*";
                }


 the string singature  wiil be like this 
60 46 59 48*59 48 59 51*59 51 59 53*59 53 60 49*60 49 61 44*61 44 62 38*62 38 64 31*64 31 67 23*67 23 70 14*70 14 72 10*72 10 75 3*75 3 77 -2*77 -2 76 2*76 2 75 6*75 6 72 17*72 17 71 24*71 24 69 31*69 31 68 46*68 46 67 59*67 59 68 71*68 71 69 79*69 79 70 86*70 86 71 89*71 89 71 93*71 93 71 95*71 95 71 97*71 97 70 95*70 95 69 88*69 88 68 81*68 81 69 77*69 77 69 68*69 68 71 60

//Saving as Image file

   Pen pen = new Pen(Color.Black);
                                 string[] arrStr = (signature.Split('*'));

                                 Graphics graphics;
                                 Bitmap bmp = new Bitmap(300, 200);

                                 graphics = Graphics.FromImage(bmp);
                                 graphics.Clear(Color.White);

                                 for (int i = 0; i < arrStr.Length - 2; i++)
                                 {
                                     string[] strArr = new string[4];
                                     strArr = ((arrStr[i].ToString()).Split(' '));
                                     graphics.DrawLine(pen, Convert.ToInt32(strArr[0].ToString()), Convert.ToInt32(strArr[1].ToString()),
                                         Convert.ToInt32(strArr[2].ToString()), Convert.ToInt32(strArr[3].ToString()));
                                 }

                                 string pathToCopyImage = systemBus.TempFile;

                                 bmp.Save(pathToCopyImage + "\\" + dsReportDetails.Tables["tblDelivery"].Rows[0]["PKDelivery"].ToString() + "_Signature.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                                 bmp.Dispose();

我的问题是,在将签名另存为图像文件后,我无法将其转换回 arrylist,就像我用来将值保存在数据库中的那个一样。即我需要将图像文件转换回如下格式

60 46 59 48*59 48 59 51*59 51 59 53*59 53 60 49*60 49 61 44*61 44 62 38*62 38 64 31*64 31 67 23*67 23 70 14*70 14 72 10*72 10 75 3*75 3 77 -2*77 -2 76 2*76 2 75 6*75 6 72 17*72 17 71 24*71 24 69 31*69 31 68 46*68 46 67 59*67 59 68 71*68 71 69 79*69 79 70 86*70 86 71 89*71 89 71 93*71 93 71 95*71 95 71 97*71 97 70 95*70 95 69 88*69 88 68 81*68 81 69 77*69 77 69 68*69 68 71 60

有人能帮我吗

4

1 回答 1

0

从图像中获取“签名字符串”并不容易,因此您只需将“字符串签名”添加到保存的图像作为图像的元数据标签(例如作为描述)。所以然后你读回你的图像,你不需要从图像中识别“签名字符串”,你可以从元数据中读取它作为字符串。Msdn 有一篇关于图像元数据和使用它们的 api 的好文章。http://msdn.microsoft.com/en-us/library/ms748873.aspx

顺便说一句,您用于连接“签名字符串”的代码很慢并且很消耗内存。在 .Net 中这种情况下最好使用 StringBuilder。并且整体字符串不是存储点列表的最佳数据结构。但这取决于您的应用程序的要求。

于 2012-04-05T06:39:17.583 回答