首页 新闻 会员 周边 捐助

将保存在数据库中的图片信息生成缩略图的问题,请大家指导!

0
悬赏园豆:20 [已解决问题] 解决于 2009-05-20 09:54
<h1 class="postTitle">我使用的是vs2003 VB.net.</h1> <div class="postBody"> <div class="blogstory"> <p>我想把保存在数据库中的图片文件,提取后,生成缩略图显示在网页上,以下是我的代码:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim con As New SqlClient.SqlConnection<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cmd As New SqlClient.SqlCommand<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim fjnr() As Byte<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.ConnectionString = dbconstring<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.Connection = con<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Open()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.CommandText = "select fjnr from L_fj where id = " &amp; fjid<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fjnr = Convert.FromBase64String(cmd.ExecuteScalar())<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sfj As New System.IO.MemoryStream(fjnr)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; img = System.Drawing.Image.FromStream(sfj,True)</p> <p>其中fjid是图片的id号,在执行Dim sfj As New System.IO.MemoryStream(fjnr)时报错,image对象生成失败。</p> <p>请各位帮忙指教。</p> </div> </div> <!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> <rdf:Description rdf:about="http://www.cnblogs.com/azeng1984/archive/2009/05/19/1460333.html" dc:identifier="http://www.cnblogs.com/azeng1984/archive/2009/05/19/1460333.html" dc:title="" trackback:ping="http://www.cnblogs.com/azeng1984/services/trackbacks/1460333.aspx" /> </rdf:RDF> -->
阿曾的主页 阿曾 | 初学一级 | 园豆:180
提问于:2009-05-19 16:38
< >
分享
最佳答案
0

cmd.CommandText = "select fjnr from L_fj where id = " & fjid
fjnr = Convert.FromBase64String(cmd.ExecuteScalar())

-----------------------------------------------------------------------------

是不是 FromBase64String 有问题?

-----------------------------------------------------------------------------

Dim sfj As New System.IO.MemoryStream(fjnr)

 img = System.Drawing.Image.FromStream(sfj,True)

------------------------------------------------------------------------------

是不是该用 Dim sfj As New System.IO.MemoryStream(fjnr, 0, fjnr.length) ?

我用 c#,乍看上去可能是二进制流的读取问题,但因为不懂 vb,所以不能确定,呵呵。

 

陛下 | 老鸟四级 |园豆:3938 | 2009-05-19 19:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册