1

我正在尝试将 PictureBox 的内容保存到数据库中。这本身效果很好,但是一旦绘制了签名图片框,它就不会设置 PictureBox.Image 属性,这意味着我无法继续该过程。

 Pen myPen;
    bool bMouseDown = false;
    Point prevPoint;
    Graphics gCust;
    Graphics gTech;

private void NewJob_Load(object sender, EventArgs e)
    {
        myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
        gCust = pbCustomerSig.CreateGraphics();
        gCust.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
        myPen.SetLineCap(LineCap.Round, LineCap.Round, DashCap.Round);
        myPen.Color = Color.Blue;
        myPen.Width = 2f;
}
public static byte[] ImageToBinary(Image image)
    {
        Byte[] buffer = (Byte[])new ImageConverter().ConvertTo(image, typeof(Byte[]));
        return buffer;
    }
private void pbCustomerSig_MouseDown(object sender, MouseEventArgs e)
    {
        prevPoint = e.Location;
        bMouseDown = true;
    }

    private void pbCustomerSig_MouseMove(object sender, MouseEventArgs e)
    {
        if (bMouseDown)
        {
            Point thisPoint = e.Location;
            if (prevPoint.X == 0 && prevPoint.Y == 0)
            {
                prevPoint = thisPoint;
                return;
            }
            gCust.DrawLine(myPen, thisPoint.X, thisPoint.Y, prevPoint.X, prevPoint.Y);
            prevPoint = thisPoint;
        }
    }

    private void pbCustomerSig_MouseUp(object sender, MouseEventArgs e)
    {
        bMouseDown = false;
    }

错误在这里 -

h.CustomerSignature = ImageToBinary(pbCustomerSig.Image);

任何想法为什么 PictureBox.Image 属性为空?

非常感谢!

4

1 回答 1

2

您没有为 分配值pbCustomerSig.Image。为空是正常的。而不是这样做尝试绘制位图。 这是在现有位图上绘制的示例,但您可以以相同的方式在空位图上绘制并同时将其显示在图片框上。

于 2013-04-21T11:13:33.487 回答