Resize image for Live Tile - WriteableBitmapEx

自古美人都是妖i 提交于 2019-12-01 09:04:50

Your problem is that you're not calculating the width/heights to a correct Aspect ratio.

So to get a 1:1 proportions, you would need a width of 134.735 pixels, for a 173 pixel height.

This can be done by first determining what side is the largest

var aspect = Math.Max(bitmapImage.Width, bitmapImage.Height)
var ratio = largest / 173;
var width = width / ratio;
var height = height / ratio;

var resizedImage = writeableBitmap.Resize(width, height, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);

And remember to set Stretch="Uniform" to avoid stretching the image to unnecessary proportions.

To create a 173x173 pixel image, with the other image applied on top, use the Blit function from WriteableBitmapEx

var tileImage = new WriteableBitmap(173, 173, ...)
tileImage.Blit(new Rect(width, height), resizedImage, new Rect(width, height), BlendMode.None);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!