1
取圖片我有這樣的代碼從SQL Server 2008數據庫的顯示圖像到一個PictureBox從數據庫
using (SqlCommand SqlCommand = new SqlCommand("Select * From Student Where StudentID = @a", myDatabaseConnection))
{
SqlCommand.Parameters.AddWithValue("@a", SearchtextBox.Text);
DataSet DS = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(SqlCommand);
da.Fill(DS, "Images");
dataGridView1.DataSource = DS.Tables[0];
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);
}
但它顯示,即使我設置了BackgroundImageLayout
伸展
我也沒有被拉伸的圖像嘗試這樣:
using (var stream = new MemoryStream(data))
{
pictureBox1.Image = Image.FromStream(stream);
pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
}
有人已經捉襟見肘:http://stackoverflow.com/questions/7920058/how-to-stretch-a-bitmap-to-fill-a-picturebox –