WP7:采集图像 [英] WP7: collection of images

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

问题描述

我在文件夹的图像的图像在我的Windows Phone解决方案。我怎样才能收集图像此文件夹中?建立所有图像的行动是内容。

I have images in folder Images in my windows phone solution. How can i get collection of images in this folder? Build Action of all images is "Content".

推荐答案

它已被窃听我,这是不可能做到这一点,所以我已经做了一些挖掘,并纷纷拿出一个得到的一种方式与资源的生成操作的所有图像文件列表。 - 是的,这是不太什么要求,但希望这仍然将是有益的。

It had been bugging me that it wasn't possible to do this so I've done a bit of digging and have come up with a way of getting a list of all image files with the build action of "Resource". - Yes, this isn't quite what was asked for but hopefully this will still be useful.

如果你真的必须使用内容的生成操作我会使用一个T4脚本生成的文件在构建时列表。 (这是我做我的项目之一,它工作正常。)

If you really must use a build action of "Content" I'd use a T4 script to generate the list of files at build time. (This is what I do with one of my projects and it works fine.)

假设图像是一个名为图片文件夹中,你可以让他们为以下内容:

Assuming that the images are in a folder called "images" you can get them with the following:

var listOfImageResources = new StringBuilder();

var asm = Assembly.GetExecutingAssembly();

var mrn = asm.GetManifestResourceNames();

foreach (var resource in mrn)
{
    var rm = new ResourceManager(resource.Replace(".resources", ""), asm);

    try
    {
        var NOT_USED = rm.GetStream("app.xaml"); // without getting a stream, next statement doesn't work - bug?

        var rs = rm.GetResourceSet(Thread.CurrentThread.CurrentUICulture, false, true);

        var enumerator = rs.GetEnumerator();
        while (enumerator.MoveNext())
        {
            if (enumerator.Key.ToString().StartsWith("images/"))
            {
                listOfImageResources.AppendLine(enumerator.Key.ToString());
            }
        }
    }
    catch (MissingManifestResourceException)
    {
        // Ignore any other embedded resources (they won't contain app.xaml)
    }
}

MessageBox.Show(listOfImageResources.ToString());

这只是显示的名称列表,但希望这将是容易改变这个做任何你需要。

This just displays a list of the names, but hopefully it'll be easy to change this to do whatever you need to.

改进本code任何建议将大大AP preciated。

Any suggestions for improving this code will be greatly appreciated.

这篇关于WP7:采集图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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