从VB.Net中的SQLite中检索BLOB [英] Retrieve a BLOB from SQLite in VB.Net
问题描述
如何在UWP中的图像源上检索和设置图像。我已经在sqlite数据库中保存了一个图像,它是blob,我想要显示它。
< Viewbox HorizontalAlignment =" Stretch" VerticalAlignment =" Stretch"
&NBSP; < Image x:Name =" ImgAds" Source =" {Binding}" /
< / Viewbox>
How to retrieve and set the image on a Image Source in UWP. I have saved an image on sqlite database it is in blob and I want to show it.
<Viewbox HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Image x:Name="ImgAds" Source="{Binding}"/>
</Viewbox>
这是我在mainpage.xaml中的代码
this is my code in mainpage.xaml
Dim NwImage As new tblImages
Dim byteConverter As New ByteToBitmapImageConverter
NwImage = GetImageBLOB(con,New tblImages,1)
ImgAds.Source = byteConverter.Convert(NwImage.Image)
公共类ByteToBitmapImageConverter
&NBSP; &NBSP; &NBSP;公共函数转换(ByVal值为对象)作为对象
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Dim imageBytes As Byte()= CType(value,Byte())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回ConvertByteToImage(imageBytes).Result
&NBSP; &NBSP; &NBSP;结束功能
&NBSP; &NBSP; &NBSP;公共函数ConvertBack(ByVal值As Object,ByVal targetType As Type,ByVal参数As Object,ByVal language As String)As Object
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;抛出新的NotImplementedException()
&NBSP; &NBSP; &NBSP;结束功能
&NBSP; &NBSP; &NBSP;私有异步函数ConvertByteToImage(ByVal imageBytes As Byte())作为任务(Of BitmapImage)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;昏暗图像As BitmapImage = New BitmapImage()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用randomAccessStream作为InMemoryRandomAccessStream = New InMemoryRandomAccessStream()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用writer As DataWriter = New DataWriter(randomAccessStream.GetOutputStreamAt(0))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; writer.WriteBytes(imageBytes)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Await writer.StoreAsync()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;等待image.SetSourceAsync(randomAccessStream)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;结束使用
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;结束使用
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回图片
&NBSP; &NBSP; &NBSP;结束功能
&NBSP;结束类
Dim NwImage As New tblImages
Dim byteConverter As New ByteToBitmapImageConverter
NwImage = GetImageBLOB(con, New tblImages, 1)
ImgAds.Source = byteConverter.Convert(NwImage.Image)
Public Class ByteToBitmapImageConverter
Public Function Convert(ByVal value As Object) As Object
Dim imageBytes As Byte() = CType(value, Byte())
Return ConvertByteToImage(imageBytes).Result
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal language As String) As Object
Throw New NotImplementedException()
End Function
Private Async Function ConvertByteToImage(ByVal imageBytes As Byte()) As Task(Of BitmapImage)
Dim image As BitmapImage = New BitmapImage()
Using randomAccessStream As InMemoryRandomAccessStream = New InMemoryRandomAccessStream()
Using writer As DataWriter = New DataWriter(randomAccessStream.GetOutputStreamAt(0))
writer.WriteBytes(imageBytes)
Await writer.StoreAsync()
Await image.SetSourceAsync(randomAccessStream)
End Using
End Using
Return image
End Function
End Class
这是我在vb中的代码
推荐答案
Hello Keith,
Hello Keith,
您的代码不完整,我无法重现您的问题。
Your code is incomplete and I can't reproduce your issue.
那么您遇到了什么错误?
So what's error you encountered?
祝你好运,
Rita
这篇关于从VB.Net中的SQLite中检索BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!