zoukankan      html  css  js  c++  java
  • WPF在DLL中读取Resource的方法

    WPF是个用户控件,被WinForm调用。而WinForm是在一个DLL类库中被调用。试了很多方法,都无法将Resource中的图读进程序。用下面的方法总算实现了。

     

    /根据图片的名称,从资源中找到它
            public static System.Drawing.Bitmap GetPngFromResources(string pngName)
            {
                /tp://www.worlduc.com/blog2012.aspx?bid=760294 c#访问Resources.resx中的资源
                ResourceManager rmManager = global::AddMenuToRevit2013.Properties.Resources.ResourceManager;
                object obj = rmManager.GetObject(pngName);
                if (obj == null)
                {
                    MessageBox.Show("未找到图片:" + pngName);
                    return null;
                }
                System.Drawing.Bitmap b = obj as System.Drawing.Bitmap;
                if (b != null)
                {
                    return b;
                }
                else
                {
                    MessageBox.Show("未找到图片:" + pngName);
                    return null;
                }
            }
    
            // System.Drawing.Bitmap要如何轉換成WPF中可用的ImageSource
            /tp://www.dotblogs.com.tw/bauann/archive/2013/04/18/101793.aspx
            public static BitmapImage BitmapToBitmapImage(System.Drawing.Bitmap bitmap)
            {
                BitmapImage bitmapImage = new BitmapImage();
                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();
                return bitmapImage;
            }
  • 相关阅读:
    wqy的ACM赛G朱柏庐
    可持久化数据结构
    LibreOJ#2362蚯蚓
    LibreOJ#2359天天爱跑步
    「Luogu2221」[HAOI2012]高速公路
    「Luogu4158」[SCOI2009]粉刷匠
    「Luogu4317」花神的数论题
    WC2019 游记
    最大权闭合子图模型
    「Luogu2762」太空飞行计划问题
  • 原文地址:https://www.cnblogs.com/xpvincent/p/3808627.html
Copyright © 2011-2022 走看看