i have a hard time from switching from winform to wpf... in winform i just easily read image using picturebox.image
byte[] imgg = (byte[])(reader["profilepic"]);
MemoryStream mstream = new MemoryStream(imgg);
pic1.Image = System.Drawing.Image.FromStream(mstream);
but in wpf picture box is not available instead an image so i tried the same code just incase it would work
void readName()
{
try
{
MySqlConnection conn = new MySqlConnection(myConnection);
conn.Open();
MySqlCommand command = new MySqlCommand("SELECT profilepic FROM maindatabase.users where user=?parameter1;", conn);
command.Parameters.AddWithValue("?parameter1", UserList.SelectedItem.ToString());
MySqlDataReader reader = command.ExecuteReader();
//int ctr = 0;
while (reader.Read())
{
//ctr++;
byte[] imgg = (byte[])(reader["profilepic"]);
MemoryStream mstream = new MemoryStream(imgg);
pic1 = System.Drawing.Image.FromStream(mstream);
//but got an error since system.drawing cant convert system.windows.control.image
//and after looking in the internet just tried this code but it doesnt seems to work too
if (imgg != null)
{
using (MemoryStream ms = new MemoryStream(imgg))
{
// Load the image from the memory stream. How you do it depends
// on whether you're using Windows Forms or WPF.
// For Windows Forms you could write:
// System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
imgPic1 = System.Drawing.Image.FromStream(ms);
}
}
else
{
MessageBox.Show("null");
}
}
}
catch
{
// MessageBox.Show("error" + ex);
}
}
xaml code
<Border BorderThickness="1"
BorderBrush="#FF000000"
VerticalAlignment="Center" Margin="10,19,158,33" Height="128">
<Image Name="pic1"
Height="128"
Stretch="Fill"
VerticalAlignment="Top" Margin="48,-1,39,-1" Width="128"/>
</Border>
i know winforms and wpf are different so i'll admit that i'm really noob at wpf so if someone can help me..thank you very much