系统错误.NotSupportedException:给定的路径's格式不被支持
本文关键字:格式 支持 NotSupportedException 路径 系统错误 | 更新日期: 2023-09-27 18:09:25
保存数据后,它通过字符串显示错误给定的路径格式不受支持,我做错了什么还是我把url
转换器代码放在错误的地方?
try
{
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = string.Format("insert into RegisterItem([Name], [Url],[Description], [Price]) values('{0}','{1}','{2}','{3}')",
ItemName.Text,
ItemUrl.Text,
ItemDescription.Text,
ItemPrice.Text);
command.ExecuteNonQuery();
MessageBox.Show("Data Saved");
txtID1.Text = txtUsername.Text;
txtName1.Text = ItemName.Text;
txtDescription1.Text = ItemDescription.Text;
txtPrice1.Text = ItemPrice.Text;
ItemName.Text = "";
ItemDescription.Text = "";
ItemPrice.Text = "";
string str = ItemUrl.Text;
pictureBox1.ImageLocation = str;
string str1 = textBox1.Text;
Image img = Image.FromFile(str);
pictureBox1.Image = img;
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
finally
{
if (Connect != null) { connect.Close(); }
}
Image img = Image.FromFile(str);
导致问题的。图像不能从Url加载,但必须是文件路径。
要从url加载图像,必须输入
WebRequest wr = WebRequest.Create("https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg");
Image img;
using (var rs = wr.GetResponse().GetResponseStream())
{
img = Image.FromStream(rs);
}
实际上,你可以完全省略
Image img = Image.FromFile(str);
pictureBox1.Image = img;
这部分代码完成了
pictureBox1.ImageLocation = str;
形象。FromFile只从磁盘文件加载,但设置ImageLocation可以从url加载,同时将图像绘制到画布