如果已经有一段图形文件的byte,调用以下过程就可以让picture控件正确显示出图片(除非你的BYTE本身就有错)
Public Function PictureFromByteStream(b() As Byte) As IPicture
    Dim LowerBound As Long
    Dim ByteCount  As Long
    Dim hMem  As Long
    Dim lpMem  As Long
    Dim IID_IPicture(15)
    Dim istm As stdole.IUnknown    On Error GoTo Err_Init
    If UBound(b, 1) < 0 Then
        Exit Function
    End If
    
    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
            Call GlobalUnlock(hMem)
            If CreateStreamOnHGlobal(hMem, 1, istm) = 0 Then
                If CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), IID_IPicture(0)) = 0 Then
                  Call OleLoadPicture(ByVal ObjPtr(istm), ByteCount, 0, IID_IPicture(0), PictureFromByteStream)
                  'main.picst.Caption = "图片显示正常"
                End If
            End If
        End If
    End If
    
    Exit Function
    
Err_Init:
'MsgBox Err.Number
    If Err.Number = 9 Then    Else    End If
End Function
现需要的是一段反转的代码,比如已经在picturebox或在image里已经有图片,不要通过存文件,读文件的方式,
直接在把图片读成一段byte.
'PBag.WriteProperty "Picture", logopic.Image
'fpicbate2 = PBag.Contents
'PBag.Contents = fpicbate2
''p2.Picture = PictureFromByteStream(fpicbate2())
'p2.Picture = PBag.ReadProperty("Picture")这样的代码虽然可以正确使用,但PBag.ReadProperty("Picture")读出来的并不是正确的byte.不要用.

解决方案 »

  1.   

    p2.Picture =PictureFromByteStream(硬盘上的文件读出来的BYTE)
    可以正常显示.
    需要的是反向,不要用存文件的方法.
      

  2.   

    貌似你需要的只是使用一下GetDIBits这个函数而已.
      

  3.   

    PropertyBag用过也观察过内存数据,它有一部份是文件头来的.文件头以后才是数据的正式开始.
      

  4.   

    好像用GdipSaveImageToStream可以实现,甚至直接在内存转JPG的byte格式....Public Declare Function GdipSaveImageToStream Lib "GDIPlus" (ByVal image As Long, ByVal Stream As Long, clsidEncoder As GUID, encoderParams As Any) As Long
    不过不会用啊?谁有相关模块的?