No imaging component suitable to complete the operation was found WPF vb.net

被刻印的时光 ゝ 提交于 2019-12-02 13:20:18

Fixed it...For anyone who faces this error in future :

  1. Make sure you're inserting the data in the proper way(sometimes corrupted data in the db causes such errors)

2 . You don't need to do some heavy coding to convert the image to byte!

Finally,let's code :

   Public Sub read()
    con.Open()
    Dim cmd As New OleDbCommand("Select * from recents", con)
    Dim _dr As OleDbDataReader
    _dr = cmd.ExecuteReader
    Dim _photo As Byte()
    While _dr.Read()
            Try
            _photo = CType(_dr(1), Byte())
            Dim strm As MemoryStream = New MemoryStream(_photo)
                Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(strm)
                Dim bi As BitmapImage = New BitmapImage()
                bi.BeginInit()
                Dim ms As MemoryStream = New MemoryStream()
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
                ms.Seek(0, SeekOrigin.Begin)
                bi.StreamSource = ms
                bi.EndInit()
            image1.Source = bi
        Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    End While
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!