oledb图像的二进制到字符串 [英] oledb image's binary to string

查看:48
本文介绍了oledb图像的二进制到字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai guys ..

i尝试从访问vb中检索数据..

正常工作

但是..当我尝试从我的访问中检索我的图像

i想知道我的代码发生了什么..

  Dim  pc 作为 字节()=  CType (rdr.Item(  picture),字节())
Dim 图片 As 图片= Nothing
使用 ms 作为 System.IO.MemoryStream(pc, True
ms.Write(pc, 0 ,pc.Length)
pictures = Image.FromStream(ms)
ms.Close()
End 使用
Form3.PictureBox1.Image = pictures



有错误告诉我''参数无效。''

 pictures = Image.FromStream(ms); 

解决方案

您的问题是写入流然后从中读取图像。在读取图像开始时,您在流中的位置就在最后;所以没有什么可读的,这会引发异常。将流回放到开头,重新打开它。



您不需要向流写入字节,它们已经存在。使用此构造函数,使用一个参数:

http://msdn.microsoft。 com / en-us / library / e55f3s5k.aspx [ ^ ]。



之后,只需阅读图片。



-SA

hai guys..
i try to retrieve data from access to vb..
everthing work normally
but.. when i try to retrieve my image from my access
i wonder what happen to my code..

Dim pc As Byte() = CType(rdr.Item("picture"), Byte())
                        Dim pictures As Image = Nothing
                        Using ms As New System.IO.MemoryStream(pc, True)
                            ms.Write(pc, 0, pc.Length)
                            pictures = Image.FromStream(ms)
                            ms.Close()
                        End Using
                        Form3.PictureBox1.Image = pictures


there is an error told me that ''Parameter is not valid.''

pictures = Image.FromStream(ms);

解决方案

Your problem is writing to a stream and then reading an image from it. At the start of reading of the image, your position in stream is at the very end; so there is nothing to read, which throws an exception. Rewind the stream back to the beginning, reopen it.

You don''t need to write bytes to the stream, they are already there. Use this constructor, with one parameter:
http://msdn.microsoft.com/en-us/library/e55f3s5k.aspx[^].

After that, just read the image.

—SA


这篇关于oledb图像的二进制到字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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