如何将图像加载到PictureBox;基于存储在DataBase中的图像位置
I have sql database where I have image as saved image location
我有sql数据库,我将图像保存为图像位置
eg:
例如:
D:\Local Pictures\Users\XXXX_XXXX_1.jpg
I am trying to place it in the picture box using this code
我试图使用此代码将其放在图片框中
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;
}
When I execute this code I am getting small x picture white background in image. How to fix and load the image
当我执行此代码时,我在图像中获得小x图像白色背景。如何修复和加载图像
2 个解决方案
#1
2
Loading:
加载:
MSDN isn't exactly clear on this matter - ImageLocation property, but it seems that setting the ImageLocation
property may not exactly load the image, so you may try to use PictureBox.Load method instead:
MSDN在这个问题上并不完全清楚 - ImageLocation属性,但似乎设置ImageLocation属性可能无法正确加载图像,因此您可能会尝试使用PictureBox.Load方法:
...
string filename = (myReader["PROFILE_PICTURE"].ToString());
profilePicBox.Load(filename);
EDIT
编辑
ImageLocation
should probably work fine, just make sure that your paths are correct and you do not use relative paths - How do I put an image into my picturebox using ImageLocation?
ImageLocation应该可以正常工作,只需确保路径正确并且不使用相对路径 - 如何使用ImageLocation将图像放入我的图片框?
Positioning and size:
定位和尺寸:
And make sure that your PictureBox properties related to size and position can handle different image sizes.
并确保与大小和位置相关的PictureBox属性可以处理不同的图像大小。
更多相关文章
- Recordset记录集对象的属性
- 要在更新属性上执行的TRIGGER?
- 使用进度条延迟加载图像会使图像在显示时发生损坏
- Android 修改用户图像笔记
- 背景图像颜色检测与Android油漆。
- Android动画精讲一:从setTranslationX谈属性动画和view动画的区别
- googlesamples/android-topeka学习笔记(一)-----一些不知道的属
- Android 基本控件的常用属性
- 想在android中使用node.js和socket.io发送图像