Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

image - Windows Phone 8 C# Load and Draw PNGs

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

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.

It should be as simple as:

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

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

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.

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. :/

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...