简体   繁体   English

字典 <string, image> ,WP8

[英]Dictionary for <string, image>, WP8

I'm trying to create a dictionary with a key/value of string / image for Windows Phone 8. 我正在尝试使用Windows Phone 8的字符串/图像的键/值创建字典。

I understand how dictionaries work, but am unsure of which type I would use for my image. 我理解字典是如何工作的,但我不确定我将使用哪种类型的图像。

Essentially, I'm trying to create 26 images, 1 for each letter of the alphabet, so that apple corresponds to an image of an apple. 基本上,我正在尝试创建26个图像,每个字母的字母为1,因此苹果对应于苹果的图像。

I'm confused with how to do this on WP8 though, so any guidance in the correct direction would be appreciated 我对如何在WP8上执行此操作感到困惑,因此任何正确方向的指导都将受到赞赏

Update: Thank you for the answer. 更新:谢谢你的回答。 I've still got to be doing something wrong here. 我仍然需要在这里做错事。 For example: 例如:

    //Set up the dictionary of AlphaImages objects. 
    if (AlphaImages == null)
    {
        AlphaImages = new Dictionary<string, BitmapImage>();
        AlphaImages.Add("Apple", new BitmapImage(@"Apple.jpg"));
    }

It claims that Im using invalid arguments for the BitmapImage. 它声称我使用BitmapImage的无效参数。 Following along with this thread, the user takes a different approach with this code: 跟随此线程,用户对此代码采用不同的方法:

Dictionary<string, Bitmap> lookup = new Dictionary<string, Bitmap>();
lookup.Add("A", new Bitmap(@"C:\08\letters\1\a1.bmp", true));

and I'm unable to get that to work as well, as the compiler spits out the same error. 而且我也无法让它工作,因为编译器会发出同样的错误。

What could I be doing wrong? 我能做错什么?

Try: 尝试:

AlphaImages.Add("Apple", new BitmapImage(new Uri("Apple.jpg", UriKind.Relative))); AlphaImages.Add(“Apple”,新的BitmapImage(new Uri(“Apple.jpg”,UriKind.Relative)));

make sure the image is set to have a Build Action of Content. 确保将图像设置为具有内容构建操作。

Air-coded. 航空编码。 :) :)

Also, see here 另外,请看这里

您正在寻找BitmapImage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM