Windows Phone 8 C#加载和绘制PNG [英] Windows Phone 8 C# Load and Draw PNGs

查看:111
本文介绍了Windows Phone 8 C#加载和绘制PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#和XAML制作一个音乐理论游戏,其中一个音符出现在五线谱上并按下相应的按钮,然后它会在一个新位置产生一个新音符,游戏玩法从那里'循环'直到你生命耗尽...等等

I'm making a music theory game with C# and XAML, where a note appears on the stave and you press the corresponding button, and then it spawns a new note in a new position and gameplay 'loops' from there until you run out of lives...etc

然而,我找不到任何能告诉我如何为Windows Phone 8加载和绘制.png文件的内容。主要问题是该位置发生了变化,我想做的就是在制作新笔记时将笔记图像显示在其中一个定义的位置。

Yet I can't find anything that tells me how to load and draw .png files for Windows Phone 8. The main issue is that the position is what changes, and all I want to do is make the note image appear at one of the defined positions when a new note is made.

应该是简单如下:

定义位置 - >加载图像 - > |:根据随机数选择随机位置 - >在选定位置绘制图像 - >如果正确,则删除图片:| ......等等

Define positions -> Load Image -> |: Select random position based on a random number -> Draw image at selected position -> if correct, remove image :| ...etc

不应该吗? (这是在XNA,但微软遗憾地已经停止了)

Shouldn't it? (it is with XNA, but Microsoft sadly have discontinued that)

我看过教程,现有问题和MSDN参考文档,但是没有Bitmap类,和System.Drawing似乎不存在。在XNA中,这个东西非常简单,但似乎不必要地复杂(或者说它太明显了)。我尝试过使用Image类,但是我找不到任何与加载或绘图有关的内容。

I've looked at the tutorials, existing questions and MSDN reference documents, but there is no Bitmap Class, and System.Drawing does not seem to exist. In XNA, this stuff was very simple, yet it seems to be unnecessarily complex (or maybe it's too obvious to point out). I've tried using the Image class, but I can't find anything to do with loading or drawing.

我只是想加载一个存储的图像本地。我已将所有笔记坐标存储在Point值中,但它正在加载和绘制图像,这是绊脚石。 :/

I'm just trying to load an image which is stored locally. I've stored all of my note coordinates in Point values, but it's loading and drawing images which is the stumbling block. :/

提前致谢。

推荐答案

有一个< a href =http://msdn.microsoft.com/en-us/library/system.windows.controls.image%28v=vs.95%29.aspx =nofollow> 图像 控制显示图片。你可以将它放在Canvas容器中,这样你就可以设置它的位置。

There is an Image control to display pictures. You can put it in a Canvas container, this way you'll be able to set its position in pixels.

<Canvas>
    <Image Source="/YourPicture.png" Canvas.Top="50" Canvas.Left="30" />
</Canvas>

您也可以通过编程方式执行此操作:

You can also do that programmatically:

var image = new Image();
image.Source = new BitmapImage(uri);
canvas.Children.Add(image);
Canvas.SetTop(image, 50);
Canvas.SetLeft(image, 30);

这篇关于Windows Phone 8 C#加载和绘制PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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