using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
myDatabaseConnection.Open();
using (SqlCommand SqlCommand = new SqlCommand("Select Photo from Employee where EmpID LIKE '%' + @EmpID + '%' ", myDatabaseConnection))
{
SqlCommand.Parameters.AddWithValue("@EmpID", textBox1.Text);
var DS = new DataSet();
var adapter = new SqlDataAdapter(SqlCommand);
adapter.Fill(DS, "Images");
var imagesTable = DS.Tables["Images"];
var imagesRows = imagesTable.Rows;
var count = imagesRows.Count;
if (count <= 0) return;
var imageColumnValue =
imagesRows[count - 1]["Image"];
if (imageColumnValue == DBNull.Value)
return;
var data = (Byte[])imageColumnValue;
using (var stream = new MemoryStream(data))
{
pictureBox1.Image = Image.FromStream(stream);
}
}
}
如果图像太大,以至于 picturebox
无法适应。使图像适合于 picturebox
的代码是什么?
我的 picturebox
是平方的,如果图像是矩形如何裁剪,并显示在像 这个这样的图片框中,图片的下半部分将被删除。