vb.net中向SQLSERVE数据库存取图片(流的形式)

本文介绍了一种将图片转换为二进制数组的方法,并提供了如何使用这些数组在应用程序中显示图片的示例代码。支持多种图片格式,如BMP、JPG、GIF等。
部署运行你感兴趣的模型镜像

  ''' <summary>
    ''' 转换成IMAGE类型
    ''' </summary>
    ''' <param name="picBox">显示照片的控件</param>
    ''' <param name="photoExt">照片的扩展名</param>
    ''' <returns>照片的二进制数组</returns>
    ''' <remarks></remarks>
    Public Function GetImageByte(ByVal picBox As PictureBox, ByVal photoExt As String) As Byte()
        Dim imgFile As New Bitmap(picBox.Image)

        Dim msStream As New MemoryStream

        Select Case photoExt.ToUpper
            Case "BMP"
                imgFile.Save(msStream, Imaging.ImageFormat.Bmp)
            Case "JPG"
                imgFile.Save(msStream, Imaging.ImageFormat.Jpeg)
            Case "GIF"
                imgFile.Save(msStream, Imaging.ImageFormat.Gif)
            Case "EMF"
                imgFile.Save(msStream, Imaging.ImageFormat.Emf)
            Case ""
                imgFile.Save(msStream, Imaging.ImageFormat.Jpeg)
        End Select

        Dim byteArray() As Byte = msStream.ToArray()
        msStream.Close()

        Return byteArray
    End Function

    ''' <summary>
    ''' 显示图片
    ''' </summary>
    ''' <param name="photoByte">照片的二进制数组</param>
    ''' <param name="picBox">需要显示图片的控件</param>
    ''' <remarks></remarks>
    Public Sub DisplayPhoto(ByVal photoByte() As Byte, ByVal picBox As PictureBox)

        If photoByte.Length > 0 Then
            Dim memory As New MemoryStream(photoByte)

            picBox.Image = Image.FromStream(memory, True, False)
        End If
    End Sub

您可能感兴趣的与本文相关的镜像

Dify

Dify

AI应用
Agent编排

Dify 是一款开源的大语言模型(LLM)应用开发平台,它结合了 后端即服务(Backend as a Service) 和LLMOps 的理念,让开发者能快速、高效地构建和部署生产级的生成式AI应用。 它提供了包含模型兼容支持、Prompt 编排界面、RAG 引擎、Agent 框架、工作流编排等核心技术栈,并且提供了易用的界面和API,让技术和非技术人员都能参与到AI应用的开发过程中

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值