zoukankan      html  css  js  c++  java
  • 使用独立的DLL来存储图片(资源文件)

    使用独立的DLL来存储图片,这样可以把我们要用的图片文件全放在一个DLL当中
    这样工程当中就只没有那么多的图片文件了
    1.在解决方案里添加一个新的class工程PicResource,然后把图片文件夹skin复制到工程目录下,并把skin包含在工程中;
           
    2.在刚才新建的工程里选中skin文件夹下的所有图片,在property中改变 Build Action 属性为 Embedded Resource;

    3.编译工程会产生一个PicResource.dll

    4.在解决方案里添加一个测试用的windowsapplication工程winAppDemo1;
    把刚才得到的PicResource.dll复制到winAppDemo1\bin\Debug下;


    5.在测试工程里的form上添加一个Button一个picturebox


    资源路径:
    <namespace>.<subfolders>.<image name>.<extension>(<命名空间>.<文件夹>.<图片名>.<后缀>)
    代码:

    private void button1_Click(object sender, EventArgs e)
    {
                Assembly myAssembly 
    = Assembly.LoadFrom("PicResource.dll");
                Stream myStream 
    = myAssembly.GetManifestResourceStream("PicResource.skin.right.bmp");
                Bitmap bmp 
    = new Bitmap( myStream );
                pictureBox1.Image 
    = bmp;

    }

    如果点完button1在picturebox里能看到图片,OK,成功了


    参考了如何嵌入图片资源?
    谢谢
    网上的一个资源http://www.wewill.cn/n20852c67.aspx

    状元@博客园

  • 相关阅读:
    NOJ 1116 哈罗哈的大披萨 【淡蓝】 状态压缩DP
    优先队列原理与实现【转】
    testC-I
    济南NOIP冬令营 选拔(select)
    P4747 D’s problem(d)
    P4746 C’s problem(c)
    P4745 B’s problem(b)
    P4744 A’s problem(a)
    [bzoj] 1004: [HNOI2008]Cards
    NOIP2013 表达式求值
  • 原文地址:https://www.cnblogs.com/lost0/p/1108608.html
Copyright © 2011-2022 走看看