I have a .net PictureBox on my screen which creates an image in real-time from a signature pad input device.
I am trying to get the bytes from the image to save but because the PictureBox is always open, I am unable to get the .Image property as it is always NULL.
Is there a way to somehow close the PictureBox so I can take the image from it?
This is where I attempt to get the bytes but the .Image is NULL due to the creation in real-time:
private void btnConfirm_Click(object sender, EventArgs e)
{
byte[] imgData = null;
// storage for the img bytes
picSignature.Update();
imgData = ImgToByteArray(picSignature.Image, ImageFormat.Jpeg);
SerialPortListener.MainForm._imagevalues = imgData;
this.Close();
}
This is the code which I believe writes the signature:
private void SignatureDataHandler(Int32 xAxis, Int32 yAxis, Int32 pressure, Int32 timeStamp)
{
long x;
long y;
Pen myPen = new Pen(Color.Black, 1);
x = (picSignature.Width * (xAxis - g_xMin)) / (g_xMax - g_xMin);
y = (picSignature.Height * (yAxis - g_yMin)) / (g_yMax - g_yMin);
if ((x > picSignature.Width) || (x < 0))
{
MessageBox.Show("problem");
}
if (0 != pressure)
{
if (g_fFirstTouch)
{
g_PicGraphics.DrawLine(myPen, x, y, x, y);
g_fFirstTouch = false;
}
else
{
g_PicGraphics.DrawLine(myPen, g_lastX, g_lastY, x, y);
}
}
else
{
g_fFirstTouch = true;
}
g_lastX = x;
g_lastY = y;
}