C# 基于位置的图像到内存流
我在DB&location中有一个以字节为单位的图像列(它存储图像的路径), 如果路径为空,我使用图像列;如果路径不为空,我将图像加载到字节数组,并从文件路径或直接字节图像列以内存流的形式返回图像C# 基于位置的图像到内存流,c#,C#,我在DB&location中有一个以字节为单位的图像列(它存储图像的路径), 如果路径为空,我使用图像列;如果路径不为空,我将图像加载到字节数组,并从文件路径或直接字节图像列以内存流的形式返回图像 //query select image,filepath from tablename; byte[] Image = { }; if(file path is not empty) { System.Net.WebClient Client = new System.Net.WebClient
//query
select image,filepath from tablename;
byte[] Image = { };
if(file path is not empty)
{
System.Net.WebClient Client = new System.Net.WebClient();
Image = Client.DownloadData("Path of the image-http://....gif");
}
else
{
Image= datareader.GetOrdinal("image");
}
如何将字节映像分配给内存流???您可以使用
MemoryStream
构造函数,该构造函数接受字节[]
实例:
byte[] data = // get data...
using (var stream = new MemoryStream(data))
{
}
如果已经有一个开放流,则只需写入数组的内容:
stream.Write(data, 0, data.Length);
谢谢,我应该从文件位置或图像(字节列数据类型)提取字节形式的图像,我有一个方法,在发送文件路径时返回字节,现在我需要的是根据文件路径的字节或图像的字节将字节分配给内存流?有什么帮助吗?还有其他方法吗?大师请。help.Sharpeye500,请解释您还需要什么-Matthew提供了用byt数组创建MemoryStream的(唯一)方法。