resource文件
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文件的更多相关文章
- 导出resource文件的的资源
写个小工具,方便一次性将resource文件中的资源导出,不然反编译后一个个找,真是太麻烦了. using System;using System.Collections.Generic;using ...
- IOS 从Resource文件夹下Copy文件到沙盒
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.t ...
- 如何在MVC的ActionLink中应用Resource文件
项目中建立Resources文件夹. 添加Resource文件,必须添加一个默认的,其他语言可以添加很多个.我这里只添加了一个中文的. 双击每个资源文件,将Access Modifier 设置成pub ...
- maven项目中没有resource文件夹的问题
之前使用eclipse创建maven项目,文件夹都是建好的,这几次创建,都没有resource文件夹,需要手动创建resource. 现象描述 在eclipse中,创建maven项目有两种方式: 一种 ...
- springboot 读取 resource文件
文件位置信息如图: import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import ...
- 遇到问题---java---myeclipse中maven项目引用另一个导致的resource文件混乱的问题
遇到情况 情况是这样的,我们在构建项目时,经常会把一些公用的类和配置提取出去,作为一个公共项目.然后把公共项目作为一个jar包构件引入我们当前的项目中. 引入方式是 <dependency> ...
- 读取ClassPath下resource文件的正确姿势
1.前言 为什么要写这篇文章?身为Java程序员你有没有过每次需要读取 ClassPath 下的资源文件的时候,都要去百度一下,然后看到下面的这种答案: Thread.currentThread(). ...
- Java读取resource文件/路径的几种方式
方式一: String fileName = this.getClass().getClassLoader().getResource("文件名").getPath();//获取文 ...
- Android开发:《Gradle Recipes for Android》阅读笔记(翻译)3.3——整合resource文件
问题: 想要在product的flavor里面改变图片,文字或者其它资源. 解决方案: 在flavor里面增加合适的资源目录,并且改变他们包含的值. 讨论: 考虑下3.2章的“hello world ...
随机推荐
- Atom 检测php错误扩展linter-php
- Google C++单元测试框架
一.概述 Google C++单元测试框架(简称Gtest),可在多个平台上使用(包括Linux, Mac OS X, Windows, Cygwin和Symbian),它提供了丰富的断言.致命和非致 ...
- Linux中断 - High level irq event handler
一.前言 当外设触发一次中断后,一个大概的处理过程是: 1.具体CPU architecture相关的模块会进行现场保护,然后调用machine driver对应的中断处理handler 2.mach ...
- this 与 super 反复问题?
我们都知道 this 和 super keyword,在 调用 构函数的时候, 都必须写在第一行中. this 调用的是当前的类的构造函数. super 调用的是父类的构造函数! this和supe ...
- Math.Celing、Math.Floor、Math.DivRem与Math.BigMul
返回大于或等于指定数字的最小整数.例如: double a=Math.Celing(0.00); //0 double a=Math.Celing(0.40); //1 double a=Math ...
- Mark 装修建材 清单
装修攻略 介绍 装修公司:东易.龙发.金螳螂.乐豪斯乳胶漆:多乐士,立邦.三棵树.晨阳水漆.华润.都芳瓷砖:马可波罗.东鹏瓷砖.蒙娜丽莎.诺贝尔.简一瓷砖.欧神诺瓷砖.金舵瓷砖.卓远瓷砖.鹰牌.兴辉瓷 ...
- html中一些常用标签及属性
html中标签分为块级标签和行级标签 块级标签常用的有 <div> <p> <h1><hr><pre><table><ul ...
- 安装ELK
1. 安装Elasticsearch a. 下载 : https://download.elasticsearch.org/elasticsearch/release/org/elasticsearc ...
- pannel加载窗体
public static void loadFillForm(Panel panel, System.Windows.Forms.Form frm) { if (frm != null && ...
- [LeetCode][Java] Search Insert Position
题目: Given a sorted array and a target value, return the index if the target is found. If not, return ...