您的位置:首页 > 编程语言 > C#

C# 把图片文件保存到程序集里(借鉴)

2014-02-08 08:57 218 查看
http://www.cnblogs.com/jljxxf/archive/2012/08/19/2646937.html

调用资源

//定义一个类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Reflection;

namespace MyImg
{
public static class ImageObject
{
/// <summary>
/// 得到要绘置的图片对像
/// </summary>
/// <param name="str">图像在程序集中的地址</param>
/// <returns></returns>
public static Bitmap GetResBitmap(string str)
{
Stream sm;
sm = FindStream(str);
if (sm == null) return null;
return new Bitmap(sm);
}

/// <summary>
/// 得到图程序集中的图片对像
/// </summary>
/// <param name="str">图像在程序集中的地址</param>
/// <returns></returns>
private static Stream FindStream(string str)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string[] resNames = assembly.GetManifestResourceNames();
foreach (string s in resNames)
{
if (s == str)
{
return assembly.GetManifestResourceStream(s);
}
}
return null;
}
}
}

//调用
Bitmap _BackImg = MyImg.ImageObject.GetResBitmap("路径");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: