若等闲
衣带渐宽终不悔,为伊消得人憔悴
  '参考:http://blog.csdn.net/freehul/archive/2005/01/19/258787.aspx
    '将Image对象和byte[]互相转换 

    
Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click
        
Dim img As Image = PictureBox1.Image
        
Dim img2 As Image = CType(GetObject(ReadObject(img)), Image)
        PictureBox2.Image 
= img2
    
End Sub


    
Public Shared Function ReadObject(ByVal obj As ObjectAs Byte()
        
Dim ms As MemoryStream = New MemoryStream
        
Dim bf As BinaryFormatter = New BinaryFormatter
        bf.Serialize(ms, obj)
        ms.Close()
        
Return ms.ToArray()
    
End Function


    
Public Shared Function GetObject(ByVal bytes As Byte()) As Object
        
Dim ms As MemoryStream = New MemoryStream(bytes, 0, bytes.Length)
        
Dim bf As BinaryFormatter = New BinaryFormatter
        
Return bf.Deserialize(ms)

    
End Function

posted on 2005-01-19 14:14  飘飘洒洒......  阅读(3319)  评论(1编辑  收藏  举报