Converter Byte() -> BitmapImage : AccessViolationException
Bonjour à tous,
J'utilise un converter perso qui me permet de traduire un tableau de byte en BitmapImage dans mes vues. En effet, je reçois mes DTO de mon webservice avec des images en type Byte().
Une fois côté client, je les traduit en BitmapImage à l'aide d'un converter dont voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
Dim param As String = parameter
If Not TypeOf value Is Byte() OrElse value Is Nothing Then
If Application.Current.Resources.Contains(param) Then
Return Application.Current.Resources(param)
Else
Return Nothing
End If
Else
Try
Dim photo As Byte() = value
Dim _photoBitmap As New BitmapImage
Using ms As New MemoryStream(photo)
ms.Seek(0, SeekOrigin.Begin)
_photoBitmap.SetSource(ms)
End Using
Return _photoBitmap
Catch ex As Exception
If Application.Current.Resources.Contains(param) Then
Return Application.Current.Resources(param)
Else
Return Nothing
End If
End Try
End If |
Malheureusement, je reçois par moments une exception AccesViolationException que je n'arrive pas à résoudre. A premiere vue, pensez vous que mon converter soit correct en terme d'accès mémoire et compagnie ? Sauriez vous d'où pourrait provenir cette exception ?
Merci d'avance