您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



vb6中如何将存在数据库中的图片数据(二进制)直接显示在image控件中?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb6中如何将存在数据库中的图片数据(二进制)直接显示在image控件中?
发表于:2008-01-17 21:14:58 楼主
请问各位高手,vb6中如何将存在数据库中的图片数据(二进制)直接显示在image控件中?需要用api实现么?
发表于:2008-01-18 16:08:171楼 得分:0

'读写二进制数据(流)
'函数名:adostream
'参数:     p_cnn   adodb连接,tabname   目标数据表,fldname   目标字段,wherestr   更新条件,
'               filename   源文件名或由流生成的文件名,rsstyle   记录集的操作类型.w:file   to   recode,r:recode   to   file
'返回值:
'例:         call     adostream(p_cnn,"achgoods","gdsphoto","where   gdsid='001'","c:\tmp.bmp","w")

public   function   adostream(p_cnn   as   adodb.connection,   _
                                                    tabname   as   string,   _
                                                    fldname   as   string,   _
                                                    optional   wherestr   as   string   =   "",   _
                                                    optional   filename   as   string,   _
                                                    optional   rsstyle   as   smrstype   =   rswrite)   as   string
       
        dim   strsql   as   string
        dim   tmpfilename   as   string
        dim   rs   as   new   adodb.recordset
        dim   adosem   as   new   adodb.stream
        dim   returnval   as   string
        dim   workpath   as   string
        dim   rstype     as   long
        dim   rsstylestr   as   string
       
        err.clear
        on   error   resume   next
       
        workpath   =   app.path
       
        if   p_cnn.state   <>   1   then   p_cnn.open
       
        if   right$(workpath,   1)   <>   "\"   then   workpath   =   workpath   &   "\"
        returnval   =   ""
        adosem.type   =   adtypebinary         '流数据类型
        adosem.open                                     '打开流
'/-----------------------------------------------------------
        '将流写入记录集
        rstype   =   rsstyle
        rsstylestr   =   choose(rstype,   "w",   "r")
        if   rsstylestr   =   "w"   then
                if   left$(trim$(ucase$(wherestr)),   len("where"))   <>   ucase$("where")   then   wherestr   =   "   where   "   &   trim$(wherestr)
                strsql   =   "select   top   1   ["   &   tabname   &   "].["   &   fldname   &   "]   from   ["   &   tabname   &   "]   "   &   wherestr
                set   rs   =   rsopen(p_cnn,   strsql,   false)     '连接式记录集
                if   not   (rs.eof   and   rs.bof)   then
                        rs.movefirst
                        adosem.loadfromfile   filename                         '将文件load到流
                        doevents
                        rs.fields(fldname).appendchunk   adosem.read
                        rs.update
                end   if
                adostream   =   ""
        elseif   rsstyle   =   "r"   then
                '/将流从记录集中取出
                if   len(trim$(filename))   =   0   then   filename   =   "tmpfile.bmp"
                if   len(trim$(dir$(tmpfilename,   vbnormal   +   vbhidden)))   >   0   then   kill   filename
                if   left$(trim$(ucase$(wherestr)),   len("where"))   <>   ucase$("where")   then   wherestr   =   "   where   "   &   trim$(wherestr)
               
                strsql   =   "select   top   1   ["   &   tabname   &   "].["   &   fldname   &   "]   from   ["   &   tabname   &   "]   "   &   wherestr
                set   rs   =   rsopen(p_cnn,   strsql)
                if   not   (rs.eof   and   rs.bof)   then
                        rs.movefirst
                        if   not   (isnull(rs.fields(fldname)))   then
                                tmpfilename   =   workpath   &   filename
                                adosem.write   rs.fields(fldname).getchunk(rs.fields(fldname).actualsize)
                                doevents
                                adosem.savetofile   tmpfilename,   iif(len(trim$(dir$(tmpfilename,   vbnormal   +   vbhidden)))   >   0,   adsavecreateoverwrite,   adsavecreatenotexist)
                                adostream   =   tmpfilename
                        else
                                adostream   =   ""
                        end   if
                else
                        adostream   =   ""
                end   if
        end   if

        if   adosem.state   =   adstateopen   then
              adosem.close
              set   adosem   =   nothing
        end   if
       
        if   rs.state   =   adstateopen   then
              rs.close
              set   rs   =   nothing
        end   if
        err.clear
end   function
发表于:2008-01-22 20:31:142楼 得分:0
感谢mstop的回复,我的意思是不要生成临时文件,直接将二进制图像流在内存中生成图像,然后调用image.picture属性显示。


快速检索

最新资讯
热门点击