1
我試圖將PictureBox的內容保存到數據庫。這本身運作良好,但是一旦簽名圖片框被繪製,它就不會設置PictureBox.Image屬性,這意味着我無法繼續該過程。使用手寫筆時PictureBox.Image爲null
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屬性爲null?
非常感謝!