如何从 Silverlight 应用程序将图像存储在 SQL Server 数据库中?
我正在尝试从 Silverlight 项目将一些图片存储到我的 SQL Server 数据库中,我需要一些帮助,所以我的问题是:
如何将图像从 url 转换为二进制以将其存储到我的数据库中(存储所有图像,而不仅仅是 url)
还有其他解决方案吗?按二进制类型? (因为SQL Server中存在图像类型)
最后,当图像存储时,如何从Silverlight中读取它?
先感谢您 。
I am trying to store some pictures into my SQL Server database from a Silverlight project, and I need some help, so my questions are:
How to convert an image to binary from a url to store it into my database (store all the image and not only the url)
Are there any other solutions, without passing by binary type? (since it exist the image type in SQL Server)
Finally, when the image is stored, how to read it from Silverlight?
Thank you in advance .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要将 System.Drawing.Image 转换为字节数组并将字节数组保存到数据库中。
要将数据从字节数组返回到 System.Drawing.Image 对象,请使用 System.Drawing.Image.FromStream(System.IO.Stream stream) 。
You'll want to convert the
System.Drawing.Image
to a byte array and save the byte array to the database.To get the data back into an
System.Drawing.Image
object from a byte array useSystem.Drawing.Image.FromStream(System.IO.Stream stream)
.下载文件内容并放入内存流中。请参阅:http://www.csharp-examples.net/download-files/
将内存流中的字节添加到数据库中
通过使用图像类和方法 FromStream 在 C# 中使用 silverlight 获取图像,请参见 http://msdn.microsoft.com/en-us/library/system .drawing.image.aspx
Download file contents and put into memory stream. See : http://www.csharp-examples.net/download-files/
Add bytes from memory stream into database
Get image with silverlight in C# by using the image class and method FromStream see http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx
http://www.pitorque .de/MisterGoodcat/post/Storing-images-in-SQL-Server-with-RIA-Services.aspx
它功能齐全,用户可以从本地磁盘选择图像并将其上传到服务它们存储在数据库中的位置。用户可以检索数据库中所有图像的列表并将其下载到客户端进行观看,并且可以从数据库中删除现有图像。
http://www.pitorque.de/MisterGoodcat/post/Storing-images-in-SQL-Server-with-RIA-Services.aspx
It is fully functional as in the user can select images from the local disk and upload them to the service where they are stored in the database. The user can retrieve a list of all images in the database and download them to the client for watching, and they can delete existing images from the database.