[英]WP7: How to downscale an image smoothly?
I'm developing a Windows Phone app (for technical reasons it must be WP7). 我正在开发Windows Phone应用程序(出于技术原因,它必须是WP7)。 I need to show images that are originally stored as hi-res PNGs, but they are shown at a smaller size. 我需要显示最初存储为高分辨率PNG的图像,但是它们以较小的尺寸显示。 I'm using an <Image>
inside a <Grid>
with star row heights. 我在具有星行高度的<Grid>
使用了<Image>
。
The problem is that the downscaled images look kind of choppy (as if the downscaling algorithm is not good), but I can't seem to find a way to show them smoothly without knowing beforehand the display size of the image and generating a new image programmatically. 问题是缩小后的图像看起来有点断断续续(好像降级算法不好),但是我似乎无法找到一种方法来平滑地显示它们,而无需事先知道图像的显示尺寸并生成新图像以编程方式。
Is there a property that I can change so that the app uses a different downscaling algorithm and so the image is only defined in XAML, or am I stuck with having to write logic in the code behind so that the image looks smooth? 是否有可以更改的属性,以便应用程序使用不同的缩小算法,从而仅在XAML中定义图像,还是我不得不在后面的代码中编写逻辑以使图像看起来平滑?
Update: I got some screenshots to show the problem. 更新:我得到了一些截图来显示问题。
<Image>
inside a <Grid>
只是<Grid>
内的<Image>
<Grid>
<Image>
inside a <ViewBox>
inside a <Grid>
<Grid>
内<ViewBox>
内的<Image>
<Grid>
ViewBox can help with scaling, but the algorithm it uses is the same, which is not useful at all to me. ViewBox可以帮助缩放,但是它使用的算法是相同的,这对我完全没有用。
See below post to re-size image this might help you 请参阅以下帖子以调整图像大小,这可能对您有帮助
The Microsoft.Phone assembly includes WriteableBitmap class, SaveJpeg()
. Microsoft.Phone程序集包括WriteableBitmap class, SaveJpeg()
。 The SaveJpeg signature looks like this: You can specify image height and width for scaling. SaveJpeg签名如下所示:您可以指定图像的高度和宽度以进行缩放。
public static void SaveJpeg(
this WriteableBitmap bitmap,
Stream targetStream,
int targetWidth,
int targetHeight,
int orientation,
int quality
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.