Récupérer une image d'une base de donnée (Linq + Blob)
Bonjour, je souhaiterais récupérer une image de ma base de données.
Voici la fonction GetImage de mon service WCF :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| public byte[] GetImage(decimal id)
{
try
{
TestDataContext db = new TestDataContext();
var image = (from i in db.IMAGEs where i.ID_IMAGES == id select i.IMAGES).SingleOrDefault();
return (image != null) ? image.ToArray() : null;
}
catch (Exception)
{
return null;
}
} |
J'utilise ensuite un objet Produit
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class Produit
{
public string Modele { get; set; }
public Byte[] Image { get; set; }
// Constructor:
public Produit(string ModeleProduit, Byte[] Img)
{
this.Modele = ModeleProduit;
this.Image = Img;
}
} |
J'ai une liste de produits :
Code:
List<Produit> produits = new List<Produit>();
Je créé un nouveau produit :
Code:
Produit produit = new Produit(Modele, ImageProduit);
Puis j'ajoute ce produit à la liste de produit :
Code:
produits.Add(produit);
Ma listBox est alimenté par cette liste de produits :
Code:
ListBoxProduit.ItemsSource = produits;
Je souhaiterais convertir mon image afin de l'afficher dans ma listbox. Voici mon code xaml :
Code:
1 2 3 4 5 6 7 8 9 10
| <ListBox x:Name="ListBoxProduit" Margin="14,184,0,40" HorizontalAlignment="Left" Width="134" ScrollViewer.VerticalScrollBarVisibility="Visible" Background="#FF131313" BorderBrush="White" Style="{StaticResource BlackStyleListBox}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="109">
<Image Source="{Binding Image}" Height="30" HorizontalAlignment="center" VerticalAlignment="center"/>
<TextBlock Text="{Binding Modele}" HorizontalAlignment="center" VerticalAlignment="center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox> |
Je voudrais savoir comment réalisé la conversion byte[] en bitmapImage.
J'ai essayé de reprendre ce tutoriel mais rien ne s'affiche.
http://blogs.msdn.com/davrous/archiv...epuis-wcf.aspx