如何从 Silverlight 应用程序将图像存储在 SQL Server 数据库中?

发布于 2025-01-05 12:20:35 字数 267 浏览 2 评论 0原文

我正在尝试从 Silverlight 项目将一些图片存储到我的 SQL Server 数据库中,我需要一些帮助,所以我的问题是:

  1. 如何将图像从 url 转换为二进制以将其存储到我的数据库中(存储所有图像,而不仅仅是 url)

  2. 还有其他解决方案吗?按二进制类型? (因为SQL Server中存在图像类型)

  3. 最后,当图像存储时,如何从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:

  1. 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)

  2. Are there any other solutions, without passing by binary type? (since it exist the image type in SQL Server)

  3. Finally, when the image is stored, how to read it from Silverlight?

Thank you in advance .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哭了丶谁疼 2025-01-12 12:20:35

您需要将 System.Drawing.Image 转换为字节数组并将字节数组保存到数据库中。

System.Drawing.Image image;
System.IO.MemoryStream imageStream;
byte[] imageBytes;

// image = your image object
imageStream = new System.IO.MemoryStream();
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); // Use whatever format your image is.
imageBytes = imageStream.ToArray();
// Save imageBytes to a DB column of type VARBINARY(MAX)

要将数据从字节数组返回到 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.

System.Drawing.Image image;
System.IO.MemoryStream imageStream;
byte[] imageBytes;

// image = your image object
imageStream = new System.IO.MemoryStream();
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); // Use whatever format your image is.
imageBytes = imageStream.ToArray();
// Save imageBytes to a DB column of type VARBINARY(MAX)

To get the data back into an System.Drawing.Image object from a byte array use System.Drawing.Image.FromStream(System.IO.Stream stream).

最终幸福 2025-01-12 12:20:35
维持三分热 2025-01-12 12:20:35

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文