我想在数据库表中显示存储为字符串的图像。当我运行代码时,我收到错误“无效的 URI,无法确定格式”。在表格中,实际的字符串是这样的:13d2dr09-377-423c-993e-22db3l390b66
我如何转换它以便可以识别它。
string sAdImageUrl = myReader.GetString(3);
var image = new BitmapImage();
int BytesToRead = 100;
WebRequest request = WebRequest.Create(new Uri(sAdImageUrl,UriKind.Absolute));
request.Timeout = -1;
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
BinaryReader reader = new BinaryReader(responseStream);
MemoryStream memoryStream = new MemoryStream();
byte[] bytebuffer = new byte[BytesToRead];
int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
while (bytesRead > 0)
{
memoryStream.Write(bytebuffer, 0, bytesRead);
bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
}
image.BeginInit();
memoryStream.Seek(0, SeekOrigin.Begin);
image.StreamSource = memoryStream;
image.EndInit();
imaPartners.Source = image;
}
}