本文介绍了C#WPF显示到画布的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好我正在使用WPF项目并且需要在画布中使用Sqlite显示图像。 Int32 i = 1 ; if (i > 0 ) { DataRow dataRow = helper.DataSet.Tables [ 0 ]。行[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(); Image MyImg = New Image(); // 将位图转换为图像 MyImg.Source = System.Windows。 Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr .Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions()); mycanvas.Children.Clear(); RemoveLogicalChild(MyImg); mycanvas.Children.Add(MyImg); 但是在mycanvas.Children.Add(MyImg)我收到错误指定的元素已经是另一个元素的逻辑子元素。首先断开它。 任何人都可以告诉我如何解决这个问题? 关注解决方案 Hi I Working On WPF Project And Need To Show Image From Sqlite In Canvas. Int32 i = 1; if (i > 0) { DataRow dataRow = helper.DataSet.Tables[0].Rows[i - 1]; //Get Bytes From DataBase byte[] imageBytes = (byte[])dataRow[8]; MemoryStream ms = new MemoryStream(imageBytes); System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(ms); IntPtr hBitmap = bmap.GetHbitmap(); Image MyImg = New Image(); //Convert Bitmap To Image MyImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); mycanvas.Children.Clear(); RemoveLogicalChild(MyImg); mycanvas.Children.Add(MyImg);But At mycanvas.Children.Add(MyImg)I Get Error "Specified element is already the logical child of another element. Disconnect it first."Can Anyone Tell Me How I Can Fix This Problem?Regards 解决方案 这篇关于C#WPF显示到画布的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-17 04:46