您好我的想法是将照片存储在SQL数据库中,我想知道如何减少图像的大小,以便它在数据库中占用太多空间。我使用SQL数据库的替代方法或?
这是我用来转换和插入图片的当前代码。
byte[] img = null;
int x,i;
private void button4_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(imgloc,FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fs);
img = reader.ReadBytes((int)fs.Length);
try
{
SqlCommand command = new SqlCommand("INSERT INTO Staff(id,Username,Password,Image) VALUES(@ID,'Nasar',0,@nasar)",connection);
command.Parameters.Add(new SqlParameter("@nasar", img));
command.Parameters.Add("@ID",i);
connection.Open();
command.ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show("An Error has accured! Please send this message to support (" + ex.Message + ")");
if(ex != null)
{
x = 1;
}
}
finally
{
if (connection != null)
{
connection.Close();
}
if (x == 0)
{
MessageBox.Show("Image has been recorded");
i++;
}
}
}