Link to home
Start Free TrialLog in
Avatar of mainrotor
mainrotor

asked on

I need help assigning an image to an image control in my VB.Net WPF project

Hi Experts,
I have a WPF application where I convert Bytes to an image.
I want to put that image in an image control in my WPF image cotrol.  Is that possible?  If so, how can I do that?

I have included my code-behing and my XAML code below.



CODE-BEHIND USED TO CONVERT BYTES TO IMAGE

For Each dr In dt
	i += 1
	listOfImageNames.Add(New KeyValuePair(Of Integer, String)(CInt(dr("ImageId")), dr("FileName")))
	If i = 1 Then
		Dim thumbData As Byte() = CType(dr("Data"), Byte())
                Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(thumbData)
                Dim myImage As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
	End If
Next

Open in new window




XAML CODE FOR IMAGE CONTROL

<Grid Margin="5 ">
        <StackPanel>
            <TextBox x:Name="txtBoxTest" />
            <Button x:Name="cmdFormats"  Height="40" Width="120" Content="Click This!!!"/>
            <Label x:Name="lblHeader" Content="Creating a custom Export..." Margin="5" FontWeight="Bold"/>
            <Label Margin="5">
	    <TextBlock TextWrapping="Wrap" Text="Select an attachment from the left (Source) ...."/>
            </Label>
            <ComboBox x:Name="ComboOfImages" HorizontalAlignment="Left" Margin="10,10,5,5" Width="320" />
            <DataGrid x:Name="dgvSource" Margin="22,171,242,10" />
            <Image x:Name="ImageXYZ" Width=" 120" Height=" 120" />
        </StackPanel>
</Grid>

Open in new window


Thank you very much for your help ind advance,
mrotor
Avatar of Alyanto
Alyanto
Flag of United Kingdom of Great Britain and Northern Ireland image

The obvious question is have you p[roved to yourself that the image from bytes works by writing the image to disk? If it does I use the INotifyPropertyChanged interface with an appropriate property.  I think that should get you most of the way there.
Avatar of mainrotor
mainrotor

ASKER

Alyanto
I will try your suggestion this week.  Thanks.  I will post my results.
ASKER CERTIFIED SOLUTION
Avatar of Alyanto
Alyanto
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial