我在表单中有一个普通的图片框,我有一张签名图片,我从数据库中恢复,当我保存带有签名的图像时,它有一个白色背景,签名是黑色的,但是当我恢复图像时,它有一个黑色背景,签名是白色的。
任何人都可以解释为什么会发生这种情况,我该如何解决?
您可以按以下方向找到图像 http://www.mediafire.com/?c91awvyrya98m2c
它包含在rar文件中:Signature.jpg
代码如下:
using System.Drawing;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
namespace WindowsFormsApplication3
{
class TestForm : System.Windows.Forms.Form
{
PictureBox oPictureBoxSignature;
public Database Db;
public TestForm()
{
Db = DatabaseFactory.CreateDatabase("DBTest");
oPictureBoxSignature = new PictureBox();
}
public bool Save_Record()
{
byte[] Signature = imageToByteArray(oPictureBoxSignature.Image);
return Save(Signature);
}
public bool Save(byte[] Signature)
{
using (DbCommand dbCmd = Db.GetStoredProcCommand("Save_Signature"))
{
Db.AddInParameter(dbCmd, "Signature", DbType.Binary, Signature);
return Db.ExecuteNonQuery(dbCmd) > 0;
}
}
public void Recover_Record(byte[] Signature)
{
oPictureBoxSignature.Image = byteArrayToImage(Signature);
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
if (byteArrayIn != null)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
else
return null;
}
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
if (imageIn != null)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
else
return null;
}
}
}