没有发现适合于完成操作的成像组件 [英] No imaging component suitable to complete the operation was found
问题描述
我使用来自我的WPF应用程序的代码将图像插入到.mdb数据库中:
Dim con As New OleDbConnection( " Provider = Microsoft.ACE.OLEDB.12.0; Data Source ="& GetCurrentDirectory()&" \ Data\rctts.mdb; Jet OLEDB:Database Password = arn33423342;")
con.Open()
Dim cmd As New OleDbCommand(" Insert into recents(Uname,Pic,Email)value(@ uname,@ pic,@ email)",con)
image1.Source = New BitmapImage(New Uri(" D:\ logo.png"))
Dim buffer As Byte()
Dim bitmap = TryCast(image1.Source,BitmapSource)
Dim encoder =新的PngBitmapEncoder()
encoder.Frames.Add(BitmapFrame.Create(bitmap))
使用stream = New MemoryStream()
encoder.Save(stream)
buffer = stream .ToArray()
结束使用
cmd.Parameters.AddWithValue(" @ pic",buffer)
`Pic`列或单元格的数据类型是OLE对象...无论如何,在插入数据后,我打开了我的数据库,我看到添加了一条新记录,但是`Pic的值`列是'长二进制数据'。无论如何,然后我继续在我的wpf应用程序中检索图像。我使用
这段代码?
Dim cmd As New OleDbCommand(" Select * from recents" con)
Dim table As New DataTable
Dim adapt As New OleDbDataAdapter(cmd)
adapt.Fill (表)
如果table.Rows.Count< = 0那么
Else
For Each row in table.Rows
recentbtn.Image.ImageSource = BytesToImage(CType(row( 1),Byte()))
recentbtn.Names.Text = table.Rows(0)(0).ToString
AddHandler recentbtn.MouseDown,AddressOf recentbtn_mousedow
RecentsList.stp.Children。添加(recentbtn)
下一个
结束如果
loadingrecents.Visibility = Visibility.Hidden
End Sub
私有共享函数BytesToImage(ByVal bytes As Byte())As BitmapImage
Dim bm = New BitmapImage()
使用stream作为MemoryStream = New MemoryStream (字节)
stream.Position = 0
stream.Seek(0,SeekOrigin.Begin)
bm.BeginInit()
bm.StreamSource = stream
bm。 CreateOptions = BitmapCreateOptions.PreservePixelFormat
bm.CacheOption = BitmapCacheOption.OnLoad
bm.EndInit()
End using
返回bm
结束函数
$
但它返回错误:没有找到适合完成操作的成像组件
$ b $ $ b $
您好,
我有一个添加和读取图像的Windows窗体项目,所使用的方法应该适用于WPF他的主要代码是代码模块。
https://code.msdn.microsoft.com/Reading-and-writing-to-MS-945a0615?redir=0
I inserted an image into a .mdb database with this code from my WPF app :
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & GetCurrentDirectory() & "\Data\rctts.mdb;Jet OLEDB:Database Password=arn33423342;") con.Open() Dim cmd As New OleDbCommand("Insert into recents(Uname,Pic,Email)values(@uname,@pic,@email)", con) image1.Source = New BitmapImage(New Uri("D:\logo.png")) Dim buffer As Byte() Dim bitmap = TryCast(image1.Source, BitmapSource) Dim encoder = New PngBitmapEncoder() encoder.Frames.Add(BitmapFrame.Create(bitmap)) Using stream = New MemoryStream() encoder.Save(stream) buffer = stream.ToArray() End Using cmd.Parameters.AddWithValue("@pic", buffer)
The `Pic` column or cell's data type is OLE Object...Anyway,after inserting the data,i opened my database,i saw that a new record was added but the value of the `Pic` column was `Long binary data`.Anyway,then i went on retrieving the image in my wpf app.I used
this code ?
Dim cmd As New OleDbCommand("Select * from recents", con) Dim table As New DataTable Dim adap As New OleDbDataAdapter(cmd) adap.Fill(table) If table.Rows.Count <= 0 Then Else For Each row In table.Rows recentbtn.Image.ImageSource = BytesToImage(CType(row(1), Byte())) recentbtn.Names.Text = table.Rows(0)(0).ToString AddHandler recentbtn.MouseDown, AddressOf recentbtn_mousedow RecentsList.stp.Children.Add(recentbtn) Next End If loadingrecents.Visibility = Visibility.Hidden End Sub Private Shared Function BytesToImage(ByVal bytes As Byte()) As BitmapImage Dim bm = New BitmapImage() Using stream As MemoryStream = New MemoryStream(bytes) stream.Position = 0 stream.Seek(0, SeekOrigin.Begin) bm.BeginInit() bm.StreamSource = stream bm.CreateOptions = BitmapCreateOptions.PreservePixelFormat bm.CacheOption = BitmapCacheOption.OnLoad bm.EndInit() End Using Return bm End Function
But it's returning an error : No imaging component suitable to complete the operation was found
Hello,
I have a windows forms project that adds and reads images, the methods used should work for WPF as the main code is in code modules.
https://code.msdn.microsoft.com/Reading-and-writing-to-MS-945a0615?redir=0
这篇关于没有发现适合于完成操作的成像组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!