Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I have a WPF application and I want to see an image to image box.
I used this code to win forms to do this
VB
 Public Sub picshow()
        Using cmd As New SqlCommand("Select * From Staff where StaffID='" & txtAA.Text & "'", GlobalClass.con)
            Using dr As SqlDataReader = cmd.ExecuteReader()
                Using dt As New DataTable
                    dt.Load(dr)
                    Try
                        Dim row As DataRow = dt.Rows(0)
                        Using ms As New MemoryStream(CType(row("Photo"), Byte()))
                            Dim img As Image = Image.FromStream(ms)
                            PictBox.Image = img '<-- Here is the problem "with Image"
                        End Using
                    Catch ex As Exception
                        GoTo err
                    End Try
                    Exit Sub
                End Using
            End Using
        End Using
        GlobalClass.con.Close()
err:
    End Sub


but it doesn't work in WPF
Can anyone help?

Thanks in advance
Posted

1 solution

Using Image in WPF

<Image Height="305" HorizontalAlignment="Left" Margin="14,53,0,0"
Name="ImageControl" Stretch="Fill" VerticalAlignment="Top" Width="390" />

Please have a look into the below link to know how to get BitmapImage from byte array

http://stackoverflow.com/questions/9564174/convert-byte-array-to-image-in-wpf[^]

Set the bitmap image as below

ImageViewer1.Source = bitmap;


Have a look into this if you are interested in using WinForm controls in WPF

http://msdn.microsoft.com/en-us/library/ms751761.aspx[^]

Other References - http://www.c-sharpcorner.com/uploadfile/mahesh/image-viewer-in-wpf/[^]
 
Share this answer
 
v2
Comments
jomachi 23-Oct-13 14:03pm    
Thanks you my friend for the responce.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900