来自图像对象的文件路径 [英] File path from image object

查看:72
本文介绍了来自图像对象的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我的资源文件夹中有一堆图片,资源文件夹中的foreach图像我创建了一个按钮,并将其背景图像设置为foreach循环的图像.

然后在按钮上单击,我将按钮上的图像传递给方法,但是我需要IMage的文件路径.

如何从图像对象获取该文件路径?

请帮忙.

预先感谢.

Hi guys.

I have a bunch of pictures in my resources folder, and foreach image in the resources folder i create a button and set its background image to the image of the foreach loop.

Then on button click i pass the image thats on the button to a method, but i need the file path of the IMage.

How do i get that file path from the image object?

Please help.

Thanks in advance.

推荐答案

不,您不需要任何图像的文件路径!这样的路径甚至不存在.您使用资源,因此将从资源字符串而不是从外部文件读取图像.

如果您使用的是.res资源,那么您已经在以书面方式进行操作:将每个图像文件分别添加到资源中,这比在Visual Studio中使用图像编辑器要好得多.但是,问题是:您的映像目录仅存在于您的项目中,它不存在于您的输出目录中,这有一个很好的理由:您的项目的某些资源文件中引用的所有文件在属性中都标记为请勿复制".在构建项目时,不应将它们复制,因为它们是嵌入式程序集的可执行模块.

但是您甚至不需要使用资源流或任何东西来读取资源.

一切都已经为您完成.在解决方案资源管理器树视图中查看树节点,它是资源文件节点的子节点. Visual Studio会为您自动生成易于使用的源代码.在编辑器中打开此文件.您会发现一个带有一些静态属性的静态类,其名称接近于带有图像的源文件的名称.类型(如果属性已经为Image).这些属性返回已准备好并准备使用的图像的实例.

只需在您的代码中使用它们即可.

—SA
No, you don''t need a file path for any images! Such path don''t even exist. You use resources, so your image will be read from the resource string, not from an external file.

If you are using .res resources, you are already doing it in a write way: you add each image file to your resource separately, which is much better for maintenance than using image editor in Visual Studio. But the thing is: you image directory exists only in your project, it does not exists in your output directory, for a good reason: all files referenced in some resource file of your project are marked as "do not copy" in the properties. They should not be copied because they are embedded is the assembly''s executable module when the project is built.

But you don''t even need to use resource stream or anything to read the resource.

Everything is already done for you. Look at the tree node in the Solution Explorer tree view, a child node of a resource file node. Visual Studio auto-generate easy-to-use source code for you. Open this file in the editor. You will find a static class with some static properties with the name close to the names of your source files with images. The type if the properties is already Image. Those properties return instanced of the images which are already prepared and ready for use.

Just use them in your code.

—SA


这篇关于来自图像对象的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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