-1
我正在使用流从数据库检索图像。需要有人来帮助我转换为字节。我的代码是 。内存流转换为字节
//connection.Open();
string sql = "SELECT Photo FROM ImageTable WHERE TagId = @ID";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@ID", tagid);
connection.Open();
object img = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
我回来之前我需要改变字节。有人请帮忙。
“字节”通常是指一个整数类型取值从0到255是你确定你想把你的图片转换成那个? – 2012-02-20 07:08:36
你知道存储在SQL中的图像格式是什么吗? PS,你可能想要从帖子中删除你的数据库连接细节 – StaWho 2012-02-20 07:09:47
Yacoder - 我GOOGLE了,发现他们改变的大部分代码字节..我只想试试它是否适用于我。你有其他更好的主意吗? StaWho - 它的varbinary(MAX)... db连接被删除... – 2012-02-20 07:15:05