调整实时图块的大小-WriteableBitmapEx [英] Resize image for Live Tile - WriteableBitmapEx

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

问题描述

**
找到了解决方案
由于这是一块图块,因此图像始终会按173拉伸到173!
为了避免这种情况,请先创建一个173 x 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);

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

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天全站免登陆