方法(将图像存储在.dll文件中) [英] How (Store images in .dll file)

查看:79
本文介绍了方法(将图像存储在.dll文件中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要问题是,我可以使用(dll库作为数据库吗?)来存储文本,图像和声音文件吗?
如果是,我该怎么做,请具体说明.
如果否-:\

--------------
预先谢谢您,等待您的回答.

My main question is can I use (dll Libraries as databases?) to store text and images and sound files maybe?
If yes- how can I do that, and please specify.
If No- :\

--------------
Thank you in advance, Awaiting your answer.

推荐答案

请参阅Kim和我对问题的评论.当您制定时,这没有任何意义.

但我希望您需要一些不同的东西:如何将图像存储在DLL之类的可执行模块中.首先,您开发的不是DLL,而是开发的程序集. DLL和EXE之间没有根本区别,DLL和EXE只是可执行文件名的一部分.将数据嵌入其中的一种方法是使用资源,尤其是* .resx资源.您甚至不需要使用资源管理器或其他工具.您最好将图像放在单独的文件中,然后将它们作为文件添加到资源中.该文件将被复制到您的项目文件系统中(因此请确保避免重复副本;您的源文件应位于项目外部或Visual Studio放置目标文件的位置),并添加到项目中对资源文件的引用.与其他数据文件不同,您的图像文件不会被复制到输出目录,而是嵌入到可执行文件中.您将获得所有引用嵌入数据的信息:查看自动生成的C#文件:您将找到一个静态类,其静态属性的名称与文件名相似或相同.如果文件是* .jpg或* .png,则属性的类型为System.Drawing.Image.只需在您的代码中使用它即可.

由于需要将可执行文件用作库,因此还需要创建一个单独的公共类,该类具有用于向用户公开图像的公共属性或方法.

但是,资源与数据库完全不同.首先,您无法在运行时对其进行修改-它们严格是只读的,因为无法修改为执行而加载的任何可执行文件.

—SA
Please see the comments by Kim and myself to the question. As you formulated it, it makes no sense.

But I hope you need something different: how to store images in the executable module like a DLL. First of all, you develop not DLLs, you develop assemblies. There is no fundamental difference between DLLs and EXEs, which are merely the parts of the executable file names. One of the ways to embed data in them is using resources, in particular, *.resx resources. You don''t even need to use Resource Manager or something. You should better put images in separate files and add them in your resource as files. The file will be copied to your project file system (so be sure to avoid having double copies; your source file should be either outside the project or at the same very location where Visual Studio puts the target file) add to the project and also add the reference to it to the resource file. Unlike other data files, your image files will not be copied to output directory but rather embedded in executable. You will get everything to reference the data embedded: look at the auto-generated C# file: you will find a static class with static property of the name similar or identical to the file name. If the file was *.jpg or *.png, the type of the property will be System.Drawing.Image. Just use it in your code.

As you need to use your executable as a library, you will also need to create a separate public class with public properties or methods used to expose the images to the user.

However, resources are not like database, not at all. First of all, you cannot modify them during run time — they are strictly read-only, as there is no a way to modify any executable file loaded for execution.

—SA


这篇关于方法(将图像存储在.dll文件中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆