Here Is My Codes I Get Image Byte Array From My DataBase And Convert It To Bitmap And When I Want Show It On Canvas I get This Error
Is There Other Way To I Convert Bitmap To Image And Show It In Canvas Box?
private void comboBox1_SelectionChanged(object sender,SelectionChangedEventArgs e)
{
selected_table_name = comboBox1.SelectedItem.ToString();
string connectionString = "Data Source=C:\\Gallery\\Appdb.sqlite";
string commandText = @"SELECT * FROM " + selected_table_name + " ORDER BY ID";
helper = new dBHelper(connectionString);
if (helper.Load(commandText, "") == true)
{
dataGridViewImageList.ItemsSource = helper.DataSet.Tables[0].DefaultView;
dataGridViewImageList.Columns[8].Visibility = System.Windows.Visibility.Collapsed;
dataGridViewImageList.Columns[6].Visibility = System.Windows.Visibility.Collapsed;
Int32 i = 1;
if (i > 0)
{
DataRow dataRow = helper.DataSet.Tables[0].Rows[i - 1];
byte[] imageBytes = (byte[])dataRow[8];
MemoryStream ms = new MemoryStream(imageBytes);
System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(ms);
IntPtr hBitmap = bmap.GetHbitmap();
MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
mycanvas.Children.Clear();
RemoveLogicalChild(MyImg);
mycanvas.Children.Add(MyImg);
}
}
}
Regards