码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2014-12-02 18:49:58      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:winform   style   blog   io   color   sp   for   on   div   

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

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控件无法显示图片问题

标签:winform   style   blog   io   color   sp   for   on   div   

原文地址:http://www.cnblogs.com/xpvincent/p/4138029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!