Resources的详情见http://www.csharpwin.com/dotnetspace/10957r3991.shtml

1.create

public static void Main()
{
ResourceWriter rw = new ResourceWriter("My.resources");
Icon ico = new Icon("Demo.ico");
Image canceloff = Image.FromFile("cancel-off.png"); rw.AddResource("demo.ico", ico); rw.AddResource("cancel-off.png", canceloff); rw.AddResource("MyStr", "从资源文件中读取字符串!");
rw.Generate();
rw.Close();
}

2.load

static Hashtable Load(string fileName)
{
if (File.Exists(fileName))
{
Hashtable resources = new Hashtable();
ResourceReader rr = new ResourceReader(fileName);
foreach (DictionaryEntry entry in rr)
{
resources.Add(entry.Key, entry.Value);
}
rr.Close();
return resources;
}
return null;
}

自己的一个例子:

  //写入资源文件内容
ResourceWriter rw = new ResourceWriter("My3.resources");
// Icon ico = new Icon("Demo.ico");
Image canceloff = Image.FromFile(@"D:\Documents\Visual Studio 2010\Projects\WebApplication1\ConsoleApplication1\bin\Debug\Application.png");
//rw.AddResource("demo.ico", ico);
rw.AddResource("Application.png", canceloff);
rw.AddResource("MyStr", "从资源文件中读取字符串!");
rw.Generate();
rw.Close(); //从资源文件里获取相应的数据
Hashtable ht =
Load(@"D:\Documents\Visual Studio 2010\Projects\WebApplication1\ConsoleApplication1\bin\Debug\My3.resources");
foreach (var VARIABLE in ht)
{
if((((System.Collections.DictionaryEntry)(VARIABLE)).Value).GetType().Name=="Bitmap")
{
Bitmap Bit = ((System.Collections.DictionaryEntry)(VARIABLE)).Value as Bitmap;
Bit.Save(@"D:\TEST.PNG", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}

resource文件的更多相关文章

  1. 导出resource文件的的资源

    写个小工具,方便一次性将resource文件中的资源导出,不然反编译后一个个找,真是太麻烦了. using System;using System.Collections.Generic;using  ...

  2. IOS 从Resource文件夹下Copy文件到沙盒

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.t ...

  3. 如何在MVC的ActionLink中应用Resource文件

    项目中建立Resources文件夹. 添加Resource文件,必须添加一个默认的,其他语言可以添加很多个.我这里只添加了一个中文的. 双击每个资源文件,将Access Modifier 设置成pub ...

  4. maven项目中没有resource文件夹的问题

    之前使用eclipse创建maven项目,文件夹都是建好的,这几次创建,都没有resource文件夹,需要手动创建resource. 现象描述 在eclipse中,创建maven项目有两种方式: 一种 ...

  5. springboot 读取 resource文件

    文件位置信息如图: import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import ...

  6. 遇到问题---java---myeclipse中maven项目引用另一个导致的resource文件混乱的问题

    遇到情况 情况是这样的,我们在构建项目时,经常会把一些公用的类和配置提取出去,作为一个公共项目.然后把公共项目作为一个jar包构件引入我们当前的项目中. 引入方式是 <dependency> ...

  7. 读取ClassPath下resource文件的正确姿势

    1.前言 为什么要写这篇文章?身为Java程序员你有没有过每次需要读取 ClassPath 下的资源文件的时候,都要去百度一下,然后看到下面的这种答案: Thread.currentThread(). ...

  8. Java读取resource文件/路径的几种方式

    方式一: String fileName = this.getClass().getClassLoader().getResource("文件名").getPath();//获取文 ...

  9. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)3.3——整合resource文件

    问题: 想要在product的flavor里面改变图片,文字或者其它资源. 解决方案: 在flavor里面增加合适的资源目录,并且改变他们包含的值. 讨论: 考虑下3.2章的“hello world ...

随机推荐

  1. atime、mtime、ctime

    当你同熟练的UNIX用户进行交谈时,你经常会听到他们傲慢地讲出术语“改变时间(change time)”和“修改时间(modification time)”.对于许多人(和许多字典而言),改变和修改是 ...

  2. Linear Algebra Courses

    Lecture 1:Demonstrate the columns of a matrix (imagine the vectors) in N-dimension space.How to mult ...

  3. spring cloud单点登录

    概述 基于springcloud的单点登录服务及基于zuul的网关服务(解决了通过zuul转发到认证服务之后session丢失问题) 详细 代码下载:http://www.demodashi.com/ ...

  4. 将Gradle项目公布到maven仓库

    将Gradle项目公布到maven仓库 1 Gradle简单介绍 1.1 Ant.Maven还是Gradle? 1.1.1 Ant和Maven介绍 全称为Apache Maven,是一个软件(特别是J ...

  5. 转载【TP3.2】:使用PHP生成二维码

    转载:在网上down了一个二维码插件PHPQRcode,整合到了ThinkPHP 3.2.3,然后写了个外部自定义函数直接调用生成二维码,根据参数不同有不同尺寸效果,整合其实挺简单,分享给大家! 今天 ...

  6. Apache POI – Reading and Writing Excel file in Java

    来源于:https://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/ In this article, ...

  7. 【LeetCode】48. Rotate Image (2 solutions)

    Rotate Image You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees ...

  8. printDocument设置适应边框打印 特重要 找了半天 设置一个属性即可

    private void pd_PrintPage(object sender, PrintPageEventArgs e) { e.Graphics.SmoothingMode = System.D ...

  9. struts2 ValueStack详解,页面获取值el表达式、ognl表达式

    http://www.blogjava.net/max/archive/2007/04/28/114417.html 我想用的是el表达式! http://www.cnblogs.com/belief ...

  10. mysql 表锁——读锁和写锁

    注意, 0.表的索引类型必须是InnoDB.相关链接:http://www.cnblogs.com/CyLee/p/5579672.html 1.如果你使用Navicat Premium,有可能会出现 ...