如何将SQL数据库中的图像转换为System.Drawing.Image?
我目前正在使用 Visual Studio 2008 (VB.Net) 和 SQL Server 2008。我将图像作为 image
保存在数据库中。当我将其提取到我的代码中时,它是一个 System.Byte[]
并且我无法将其转换为 System.Drawing.Image
以保存到我的 DevExpress(v10 .2).XtraEditors.ImageEdit。
我已经尝试过
Dim imgStream As MemoryStream = New MemoryStream(image, 0, image.Length)
,
Dim imgStream As MemoryStream = New MemoryStream(image)
但即使如此,我也无法调用 image.FromStream(imgStream)
或 bitmap.FromStream(imgStream)
因为我收到“参数无效”当我尝试时。
编辑:
我们正在从 SQL 2000 上的先前系统进行更新。当我运行先前的程序时,我可以在程序中看到图像。当我运行新的图像时,我迁移的任何图像都是“无效参数”,但我添加到数据库(通过程序上的输入)的任何图像都是可见的。当我从旧数据库和新数据库中获取图像时,它们是完全相同的。迁移数据时我应该考虑 SQL 2000 和 SQL 2008 之间的区别吗?
I am currently using Visual Studio 2008 (VB.Net) and SQL Server 2008. I have images saved on the database as image
. When I fetch it into my code it is a System.Byte[]
and I am unable to cast it as a System.Drawing.Image
to save to my DevExpress(v10.2).XtraEditors.ImageEdit.
I have tried to
Dim imgStream As MemoryStream = New MemoryStream(image, 0, image.Length)
or
Dim imgStream As MemoryStream = New MemoryStream(image)
Yet even then I am unable to call image.FromStream(imgStream)
or bitmap.FromStream(imgStream)
as I get a "Parameter is not valid" when I try.
EDIT:
We are updating from a previous system that was on SQL 2000. When I run the previous program I can see the image in the program. When I run the new one any image that I migrated is an 'invalid parameter' yet any image I added to the database (through the input on the program) is viewable. When I fetch the image from the old database and the new one they are the exact same. Is there a difference between SQL 2000 and SQL 2008 that I should take into account when migrating the data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下:
但是,此错误通常意味着您的输入数据无效。您如何确定您的字节数组包含有效的图像数据?
Try this:
However, this error usually means that your input data is invalid. How sure are you that your byte array contains valid image data?