您的位置:程序门 -> vb -> 多媒体



关于如何在vb读取图像?急


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


关于如何在vb读取图像?急[已结贴,结贴人:zwwall]
发表于:2008-01-10 21:02:13 楼主
//这是一视频卡开发包一个ocx方法。      
hresult   onbufferremovenoise([in,   out]   long   *   p_buffer,   [in]   long   p_len,   [in]   long   p_width,  

[in]   long   p_height   );

描述  

调用createremovenoiseevent函数之后会产生一次该事件

获取一个去除噪声点帧buffer,这是线程事件,请小心处理  

通常利用这个事件捕获图片

long   *   p_buffer     帧buffer,使用时必须强制转换成byte   *

                            如:

                            byte   *buffer=(byte   *)   p_buffer;

long   p_len             帧buffer   大小

long   p_width,   long   p_height

帧宽度和高度

通常是24bit帧,p_len=   p_width   *   p_height   *3
===================================
       
    请问如何在vb中调用此方法,并且在将图像用jpg页格式保存到电脑中.  
发表于:2008-01-10 21:11:221楼 得分:0
急啊,明天就要交货了.

大家帮帮忙啊.小弟先感谢大家了~
发表于:2008-01-10 22:52:332楼 得分:0
純商業應用哦
发表于:2008-01-11 09:06:563楼 得分:0
大家帮帮忙啊,一客户吹得急.

分不够再加.
发表于:2008-01-11 09:42:134楼 得分:100
创建一个hdib,然后将buffer复制到dib里去,然后可以将hdib转换成stdpicture对像,就可以用savepciteru方法保存为jpg.要不直接处理hdib的话,用gdi+也可以,ijl15库也可以压缩,俺blog下载的那里那个远程屏幕的代码中,也有一个老外写的纯vb代码jpg算法模块
发表于:2008-01-11 09:49:055楼 得分:0
lorl2  
money  
等   级:
  发表于:2008-01-11   09:42:134楼   得分:0  
创建一个hdib,然后将buffer复制到dib里去,然后可以将hdib转换成stdpicture对像,就可以用savepciteru方法保存为jpg.要不直接处理hdib的话,用gdi+也可以,ijl15库也可以压缩,俺blog下载的那里那个远程屏幕的代码中,也有一个老外写的纯vb代码jpg算法模块  
 
================================================================
第一次编写这个,不懂啊.

你的blog地址多少啊,看看例子.先谢了~
发表于:2008-01-11 10:06:376楼 得分:0
blog.csdn.net/lorl2
发表于:2008-01-11 22:05:557楼 得分:0
lorl2  
money  
等   级:

==================================
请问为什么我得到的p_buffer转换成图片,黑黑的什么数据都没有.

代码如下:

private   sub   ckdsvideo1_onbufferremovenoise(p_buffer   as   long,   byval   p_len   as   long,   byval   p_width   as   long,   byval   p_height   as   long)
'on   error   goto   err
'     dim   ok   as   boolean
'
    dim   ok   as   boolean
   
        ok   =   copyscreentobmp(app.path   +   "\test.bmp",   p_buffer)
        if   ok   then
                set   picture1.picture   =   loadpicture(app.path   +   "\test.bmp")
        else
                msgbox   "cao,拷屏失败了~"
        end   if

end   sub

public   function   copyscreentobmp(byval   szfile   as   string,   pbuff   as   long)   as   boolean
    dim   w   as   long,   h   as   long
    dim   scrdc   as   long
    dim   dib   as   long,   m_dc   as   long
    dim   bmpinfo   as   bitmapinfoheader
    dim   bmpfilehead   as   bitmapfileheader
    dim   pdata   as   long
    dim   buff()   as   byte
    dim   old   as   long
    dim   l   as   long
        '取屏幕   高宽
        w   =   320
        h   =   240
        '准备内存dc
        m_dc   =   pbuff
        'm_dc   =   -2073673710
        if   m_dc   =   0   then
                copyscreentobmp   =   false
                exit   function
        end   if
        '填充dib的bmp结构
        with   bmpinfo
                .bibitcount   =   24
                .biplanes   =   1
                .biheight   =   h
                .biwidth   =   w
                .bisize   =   40   '本结构长度
        end   with
       
        dib   =   createdibsection(m_dc,   bmpinfo,   dib_rgb_colors,   pdata,   0,   0)
        if   dib   =   0   then
                deletedc   m_dc
                copyscreentobmp   =   false
                exit   function
        end   if
       
        old   =   selectobject(m_dc,   dib)
        '拷屏
        scrdc   =   getdc(m_dc)
        bitblt   m_dc,   0,   0,   w,   h,   scrdc,   0,   0,   srccopy
       
       
        '补足4的倍数
        l   =   (w   *   3   +   3)   and   &h7ffffffc
        l   =   l   *   h
        '分配内存
        redim   buff(1   to   l)   as   byte
       
       
        '取像素数据
        copymemory   varptr(buff(1)),   pdata,   l
       
        '释放资源
        selectobject   m_dc,   old
        deleteobject   dib
        deletedc   m_dc
        releasedc   0,   scrdc
        '填充bmpfile
        with   bmpfilehead
                'bm标志
                .bftype(0)   =   66:   .bftype(1)   =   77
                .bfsize   =   54   +   l                 '本文件大小
                .bfoffbits   =   54                   '像素数据偏移地址
        end   with
       
        '写入文件
        '懒得声明变量,直接用   l   存放文件号
        l   =   freefile()
        open   szfile   for   binary   as   l
        '写入文件头
        put   l,   1,   bmpfilehead
        put   l,   ,   bmpinfo
        '写入实际像素
        put   l,   ,   buff()
        close   l
       
        copyscreentobmp   =   true

end   function
发表于:2008-01-12 09:41:258楼 得分:0
vb.net code
上面这个copyscreentobmp的涵数是拷屏的,不是转换的 你可以这样 pbuffer是指向你的图像数据的指针,那么你,在你己知图像长宽的情况下,就可以用createdibsection创建一个与它一样的dib,然后利用copymemory将pbuffer指向的数据拷到dib中,olecreatepictureindirect这个api就可以将这个dib在内存中转换成vb的stdpicture对像.调用savepicture方法,就可以直接保存成jpg或bmp了 创建dib的方法 假设开发包传过来的图像是24位的,320x280,那么可以这样 with bmpinfo .bibitcount = 24 .biplanes = 1 .biheight = 280 ' .biwidth = 320,宽 .bisize = 40 '本结构长度 end with hdib = createdibsection(m_dc, bmpinfo, dib_rgb_colors, pdata, 0, 0) '这时候就得到一个hdib,但它里面没有内容,pdata是指向它的像素数据的指针, 然后我们就可以用copymemory将图像写入dib copymemory pdata, pbuffer, pbuffer的字节数 调用下面这个涵数转成vb的stdpicture dim mypicture as stdpicture mypicture = createbitmappicture(hdib, 0, itype) dim szfile as string szfile="c:\test.jpg" call savepicture(szfile) 下面是一段网友写的位图句柄转成stdpicture的代码 private declare function olecreatepictureindirect lib "olepro32.dll" (picdesc as picbmp, refiid as guid, byval fpictureownshandle as long, ipic as ipicture) as long private type guid data1 as long data2 as integer data3 as integer data4(7) as byte end type private type picbmp size as long type as long hbmp as long hpal as long reserved as long end type private function createbitmappicture(byval hbmp as long, byval hpal as long, byval itype as integer) as picture dim r as long, pic as picbmp, ipic as ipicture, iid_idispatch as guid 'fill guid info with iid_idispatch .data1 = &h20400 .data4(0) = &hc0 .data4(7) = &h46 end with 'fill picture info with pic .size = len(pic) ' length of structure .hbmp = hbmp ' handle to bitmap .hpal = hpal ' handle to palette (may be null) if itype = 0 then .type = vbpictypebitmap ' type of picture (bitmap) else .type = vbpictypeicon end if end with 'create the picture r = olecreatepictureindirect(pic, iid_idispatch, 1, ipic) 'return the new picture set createbitmappicture = ipic end function 使用方法: set youpicture = createbitmappicture(hbmp, 0, itype) 其中: youpicture 为你要的stdpicture对象 hbmp 为你已得到的位图的句柄 itype 为vbpictypebitmap(位图)或 vbpictypeicon(图标)
发表于:2008-01-12 09:43:469楼 得分:0
哎,savepicture那里少填了个变量


快速检索

最新资讯
热门点击