使用网络摄像头捕获图像,并通过vb.net中的图片框将图像保存在sql数据库中 [英] Capture Image using webcam and saving the image in sql database through a picturebox in vb.net

查看:113
本文介绍了使用网络摄像头捕获图像,并通过vb.net中的图片框将图像保存在sql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我正在开发一个项目,用户数据存储在sql db中,同时使用网络摄像头拍摄的图像。

我已经完成了成功捕获图像并存储在图片框中的部分,但是图片框中的图像没有传递到sql表中,这部分给出了错误。



这是我的代码将picturebox图像插入sql数据库



  Dim  cmd < span class =code-keyword> As   SqlCommand(  INSERT INTO detail4 VALUES(@ tag,@ pic),sql)
cmd.Parameters.AddWithValue( @ name,Button1.Text)
Dim ms 作为 MemoryStream()
PictureBox1.BackgroundImage.Save(ms,Pict ureBox1.BackgroundImage.RawFormat)
Dim data As 字节()= ms.GetBuffer()
Dim p As < span class =code-keyword>新 SqlParameter( @ photo,SqlDbType .Image)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
MessageBox.Show( 名称&图像已保存 保存,MessageBoxButtons.OK)





i得到错误

PictureBox1.BackgroundImage.Save(ms,PictureBox1.BackgroundImage .RawFormat)



是因为rawformat ...请帮助...

解决方案

你好,



尝试:

 PictureBox1.BackgroundImage.Save(ms,System.Drawing.Imaging.ImageFormat .Bmp)



希望这会有所帮助。


当我使用存储过程将图像插入sqldatabase时,它会在PictureBox1中出错。 BackgroundImage.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg)错误是

>对象引用未设置为对象的实例。

Hi everyone.
I am working on a project where user data is stored in sql db along with its image which is captured using a webcam.
I have finished the part where image is captured successfully and stored in picturebox, but the image from picturebox doesn't pass into the sql table, this part gives an error.

this is my code to insert picturebox image into sql database

Dim cmd As New SqlCommand("INSERT INTO detail4 VALUES(@tag,@pic)", sql)
cmd.Parameters.AddWithValue("@name", Button1.Text)
Dim ms As New MemoryStream()
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)
Dim data As Byte() = ms.GetBuffer()
Dim p As New SqlParameter("@photo", SqlDbType.Image)
p.Value = data
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery()
MessageBox.Show("Name & Image has been saved", "Save",MessageBoxButtons.OK)




i get an error at
PictureBox1.BackgroundImage.Save(ms, PictureBox1.BackgroundImage.RawFormat)

is it because of rawformat... pls help...

解决方案

Hi,

Try:

PictureBox1.BackgroundImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)


Hope this helps.


When i insert image into sqldatabase using store procedure it gives an error at "PictureBox1.BackgroundImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)" error is
>Object reference not set to an instance of an object.


这篇关于使用网络摄像头捕获图像,并通过vb.net中的图片框将图像保存在sql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆