ImageオブジェクトからBLOB(バイト配列)を生成する

ImageオブジェクトからデータベースのBLOB型を生成するためにMemoryStreamへ保存し バイト配列へ変換します。

実装例

Public Shared Function Image2BLOB(ByVal imgSrc() As System.Drawing.Image, _
                           ByVal format As System.Drawing.Imaging.ImageFormat) As Byte()
    Dim imgDest As System.Drawing.Image
    Dim bytBlob() as Byte

    Using stm As New System.IO.MemoryStream()
        imgSrc.Save(stm, format)
        bytBlob = stm.ToArray()
    End Using

    Return bytBlob
End Function