解决嵌入WinForm的WPF控件无法显示图片问题

解决办法是在控件初始化时,通过下面方法再次加载图片:

ucCanvas.CreateCoordinateImage.Source = GetImageIcon(global::MainApplication.Properties.Resources.DL_Coordinate2);
private static BitmapImage GetImageIcon(System.Drawing.Bitmap bitmap)
        {
            BitmapImage bitmapImage = new BitmapImage();

            try
            {

                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                bitmap.Save(ms, bitmap.RawFormat);
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = ms;
                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
                bitmapImage.Freeze();


            }
            catch (Exception ex)
            {

                Utilities.ShowExceptionMessage(ex);
            }

            return bitmapImage;
        }

解决嵌入WinForm的WPF控件无法显示图片问题

上一篇:C#复习一( Twenty Days)


下一篇:FastDFS的配置、部署与API使用解读(4)FastDFS配置详解之Client配置