buffer[]是一个采集的API后到的图片数据,如果显示在picture里?

解决方案 »

  1.   

    先buffer[]中二进制数据写成一个图片文件,比如12.bmp,再加载到picture里
      

  2.   

    可以使用Stream方式来处理,Buffer是Byte类型的数组吧?
    http://download.csdn.net/source/1483930
      

  3.   

    buffer是byte,下面是我的定义Public pbyteImageBuffer() As Byte
      

  4.   

    参考1楼Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, ppstm As Any) As Long
    Private Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, riid As Any, ppvObj As Any) As Long
    Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As Any) As Long
    Private Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)Public Function PictureFromByteStream(b() As Byte) As IPicture
        
        Dim hMem        As Long
        Dim lpMem       As Long
        Dim LowerBound  As Long
        Dim ByteCount   As Long
        Dim IID_IPicture(15)
        Dim istm        As stdole.IUnknown
        
        LowerBound = LBound(b)
        ByteCount = UBound(b) - LowerBound + 1
        
        hMem = GlobalAlloc(&H2, ByteCount)
        
        If hMem <> 0 Then
            
            lpMem = GlobalLock(hMem)
            
            If lpMem <> 0 Then
                
                MoveMemory ByVal lpMem, b(LowerBound), ByteCount
                
                GlobalUnlock hMem
                
                If CreateStreamOnHGlobal(hMem, 1, istm) = 0 Then
                    
                    If CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), IID_IPicture(0)) = 0 Then
                        
                        OleLoadPicture ByVal ObjPtr(istm), ByteCount, 0, IID_IPicture(0), PictureFromByteStream
                        
                    End If
                    
                End If
                
            End If
            
        End If
        
    End Function声明:非本人原创
      

  5.   

    另一种思路:
    利用API函数在内存中建立一个虚拟图片,再将该图片复制到picturebox即可,好处在于不用生成文件,速度也很快。
      

  6.   

    http://www.m5home.com/bbs/thread-2688-1-1.html如果字节数组是一个完整的文件内容,则可以使用这个模块.
      

  7.   

    '假设Form 上已经存在Picture1的控件,并已经设置好图片Dim PBag As New PropertyBag
    Dim B() As Byte'PBag.WriteProperty "Picture", Picture1.Picture
    '读取Picture1.Picture 图片并写到 Pbag 容器中
    在这里从相机上采集数据到B数组.
    B = PBag.Contents '获取容器Byte 到 B() 数组中
    '这时 B 就时我们想要获得的Byte数组
    '读取 Byte() 数组内容到 PicturePBag.Contents = B '指定 PBag容器的内容'读取容器中的图片
    Set Picture1.Picture = PBag.ReadProperty("Picture")但以上PBag.Contents = B 就会出错,提示无效的过程或调用的函数
      

  8.   


    frmMain.Picture1(Che).Picture = PictureFromBits(pbyteImageBuffer())
    这个模块引用了,没反应.图像没显示
      

  9.   

    用Stream方式会不会慢呢?因为我是实时采集CCD上的图像用Picture显示出来
    积分为0下载不了.
      

  10.   

    我觉得你最好先查一下你调用的那个API返回的这个字节数组里的东西是什么格式为好.都不清楚是什么情况,贸然出招想解决问题,只能是在碰运气.....
      

  11.   

    正解!
    比如三个字节01 02 03
    到底表示
    ·黑白像素8x3
    ·灰度级像素3x1
    ·RGB像素1x1
    ·……
    有无限多中可能
      

  12.   

    图像是灰度的与设备无关的位图(DIB)