zoukankan      html  css  js  c++  java
  • .NET 下各种Resource的读取方式

    1) Embedded Resource (Build Action 设置为 Embedded Resource) 在运行时使用GetManifestResourceStream读取

    Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsFormsApplication1.Properties.Resources.warning.png"));

    2) Resource (Build Action 设置为 Resource) 在运行时使用 Resource Manager读取

    ResourceManager rm = new ResourceManager("WindowsFormsApplication1.g", typeof(Form1).Assembly);

    Image warImg = null;
    ResourceSet rs= rm.GetResourceSet(new System.Globalization.CultureInfo("en"),true,true);
    foreach (DictionaryEntry item in rs)
    {
            Console.WriteLine(item.Key.ToString());

            warImg = Bitmap.FromStream(item.Value as Stream);

    }

    3) 如果是直接添加图片到.Resx资源文件中,在运行时使用Resource Manager读取, 但读取方式有不同

    ResourceManager rm = new ResourceManager("WindowsFormsApplication1.Properties.Resources", typeof(Form1).Assembly);

    Bitmap warnImg = rm.GetObject("warning") as Bitmap;

    以上是WinForm 和 WPF下的情况,在ASP.NET下还有另外一种嵌入资源方式,通过WebResourceAttribute, NOTE: 这里的image的build action必须是Embedded Resource.

    添加 assembly attribute:

    [assembly: WebResourceAttribute("ServerControl1.images.component.gif", "image/gif")]

    客户端读取:

    string imgURL = Page.ClientScript.GetWebResourceUrl(typeof(ServerControl1), ("ServerControl1.images.component.gif");

  • 相关阅读:
    The Tower of Hanoi
    POJ 3259:Wormholes
    第二数学归纳法
    Josephus Problem
    想成为Java高手的25个学习目标
    How to find a cycle of length 4?
    Fabonacci Numbers
    通过参数离线安装SharePoint 2010[转]
    Sharepoint2010文档库权限问题
    BizTalk 2010 学习笔记——第一章 BizTalk 2010 概述
  • 原文地址:https://www.cnblogs.com/ShaYeBlog/p/4799257.html
Copyright © 2011-2022 走看看