简体   繁体   中英

Unable to play Sprite Images with aspect ratio in Windows Phone 8

I am trying to play sprite images on windows phone 8. But its not playing correctly, if the single sprite image is larger than screen dimensions. I try to reduce the image with aspect ratio by using rectangle and ImageBrush. Still I am facing the same problem. Please find the below scenario.

Scenario : Sprite Width/Height : 22100 / 516

Single Sprite Width/Height : 850/516

Mobile Dimensions : 800/480

Could anyone can help me out.

So, if I understood your question, all you need to do is:

  1. Create a BitMapImage , don't use ImageBrush or Rectangle ..

     BitmapImage bitmapImage = new BitmapImage(); bitmapImage.UriSource = new Uri(imagePathOrUrl, UriKind.RelativeOrAbsolute);
  2. I suggest you to add also this instruction to prevent memory issues:

     bitmapImage.DecodePixelWidth = imageWidth;
  3. Add the BitMapImage to an Image control and set the **Stretch** property for the aspect ratio:

     Image img = new Image(); img.Source=bitmapImage; img.Stretch = Stretch.Uniform;

Stretch property has also other values, so be sure to do some test with the other values to see what value adapts better to your needs.

Let me know if it works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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