你捕获的是什么类型,Image吗?
解决方案 »
- 两个文本框联动的问题。
- |ZYCWPF| WPF如何修改RichTextBox的右键菜单,现在RichTextBox右键有剪切,复制,粘贴,如果我想再加要怎么办 谢谢
- XP机器上安装了vs2008,在form上添加一个水晶报表控件。
- c#中有没有类似VB 里的 MSHFlexGRID 控件
- C#调用C++????
- Appearance属性为Normal,C#2005里面ToolBar控件的按钮为何不能立体化显示
- c# excel 分散区域合成一个range
- 请问如何序列化类到数据库字段和如何反序列化?
- 一行 c 代码翻译到C# typedef void (* afunc)(void);
- 我想做一个程序,其中有从文本中向SQLSERVER写入数据,然后从数据库中倒出纪录到EXCEL中,有没有例子或给点建议
- c#
- 大家帮我看看这句话怎么错了
/// 从文件读取 Stream
/// </summary>
public Stream FileToStream(string fileName)
{
// 打开文件
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
// 读取文件的 byte[]
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
// 把 byte[] 转换成 Stream
Stream stream = new MemoryStream(bytes);
return stream;
}
using (FileStream fs = new FileStream("D:\\12345.jpg", FileMode.Open))
{
imagebytes = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
}
SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True"); con.Open(); string sql = "insert into b(ID,zhiwu,picture)values(@ID,@zhiwu,@picture)";
System.Data.SqlClient.SqlParameter[] para = new System.Data.SqlClient.SqlParameter[] {
new System.Data.SqlClient.SqlParameter("@ID",12),
new System.Data.SqlClient.SqlParameter("@zhiwu","dahui"),
new System.Data.SqlClient.SqlParameter("@picture",imagebytes)
}; //string sql = string.Format("insert into b(ID,zhiwu,picture)values({0},'{1}',{2})", 9, "xiaohuilang", imagebytes); SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddRange(para);
int resulet = cmd.ExecuteNonQuery();
con.Close();
取 byte[] imagebytes = null; SqlConnection con = new SqlConnection("Data Source=FCSDL-DT-002\\SQLEXPRESS;Initial Catalog=stuDB;Integrated Security=True"); con.Open(); string sql = "select * from b where ID=11"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{
imagebytes = (byte[])read["picture"];
}
read.Close();
con.Close(); MemoryStream ms = new MemoryStream(imagebytes);
Bitmap bmpt = new Bitmap(ms);
this.pictureBox1.Image = bmpt;
MemoryStream ms=new MemoryStream();
img.Save(ms, ImageFormat.Jpeg);//img为你的图片
byte[] byt = new byte[ms.Length];
byt = ms.GetBuffer();
Image images = picturebox1.Image;
我这里没摄像头不能帮你试。
这个应该可以。
http://blog.sina.com.cn/s/blog_6ca9cc1f0100pi0d.html