调整动态磁贴的图像大小 - WriteableBitmapEx [英] Resize image for Live Tile - WriteableBitmapEx

查看:19
本文介绍了调整动态磁贴的图像大小 - WriteableBitmapEx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**
找到解决方案
由于这是一个平铺,图像将始终被拉伸到 173 x 173!
为了避免这种情况,首先创建一个 173 × 173 的虚拟对象,然后将其与调整大小的对象合并!

**
Found the solution
Because of the fact this is a tile, the image will always be strechted to 173 by 173!
To avoid this first create a dummy 173 by 173 and merge this with the resized one!

Rect rect = new Rect(0.0, 0.0, width, height);
WriteableBitmap bitmapDummy = new WriteableBitmap(173, 173);
bitmapDummy.Blit(rect, resized, rect, WriteableBitmapExtensions.BlendMode.None);

**

好吧,我已经创建了一个后台代理来更新我的 WP7 应用程序的实时磁贴.但是无论我尝试调整它的大小,我都没有得到好的结果!

Well I have created a Background agent to update the live tile of my WP7 app. But no matter what I try to resize it, I'm not getting a good result!

有什么建议吗?目前我有以下代码,但我也尝试了 135 x 173 和其他插值.

Any tips? Currently I have following code, but I also tried 135 by 173 and also the other Interpolation.

WriteableBitmap writeableBitmap = new WriteableBitmap(bitmapImage);
var resized = writeableBitmap.Resize(173, 173, System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);

下面还添加了一个小矩形来显示应用程序的标题!它的高度为 40 像素,如果图像在上方裁剪会很棒.实际图像始终为 250 x 321 像素

There is also a small rectangle added below to show the title of the app! It's 40px in height, would be great if image would be cropped above. The actual image is always 250 by 321px

推荐答案

你的问题是你没有计算出正确的宽度/高度 纵横比.

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

因此,要获得 1:1 的比例,您需要宽度为 134.735 像素,高度为 173 像素.

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

并记住设置 Stretch="Uniform" 以避免将图像拉伸到不必要的比例.

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

要创建一个 173x173 像素的图像,并将另一个图像应用在顶部,请使用 WriteableBitmapEx

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

这篇关于调整动态磁贴的图像大小 - WriteableBitmapEx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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