我有sql数据库,我在其中将图像保存为图像位置
例如:
D:\Local Pictures\Users\XXXX_XXXX_1.jpg
我正在尝试使用此代码将其放在图片框中
DataConnection myCon = new DataConnection(); // Contains Data Connection String
SqlConnection con1 = new SqlConnection(@"Data Source=.\SQLS2012;Initial Catalog=test;Integrated Security=True");
con1.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT * From USER_TABLE WHERE USERID =" + userIdTextBox.Text,con1);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
nameTextBox.Text = (myReader["FIRST_NAME"].ToString());
lnameTextBox.Text = (myReader["LAST_NAME"].ToString());
posTextBox.Text = (myReader["POSITION"].ToString());
emailTextBox.Text = (myReader["E_MAIL"].ToString());
phoneTextBox.Text = (myReader["PHONE"].ToString());
usernameTextBox.Text = (myReader["USERNAME"].ToString());
userLevelTextBox.Text = (myReader["USER_LEVEL"].ToString());
string filename = (myReader["PROFILE_PICTURE"].ToString());
profilePicBox.ImageLocation = filename;
}
当我执行此代码时,图像中的x图片变成白色背景。如何修复和加载图像
载入中:
MSDN尚不十分清楚-ImageLocation属性,但似乎设置该ImageLocation
属性可能无法完全加载图像,因此您可以尝试使用PictureBox.Load方法代替:
...
string filename = (myReader["PROFILE_PICTURE"].ToString());
profilePicBox.Load(filename);
编辑
ImageLocation
应该可以正常工作,只需确保您的路径正确并且不使用相对路径-如何使用ImageLocation将图像放入图片框?
位置和尺寸:
并确保与大小和位置有关的PictureBox属性可以处理不同的图像大小。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句