如何在uwp的xaml中拉伸/调整svg的大小? [英] how to stretch/resize svgs in uwp's xaml?

查看:176
本文介绍了如何在uwp的xaml中拉伸/调整svg的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自创建者更新发布以来,uwp可以使用svg图像,如简要说明

Since the creators update came out, uwp can use svg images as briefly explained here (minute 3).

我有此svg (48x48 ),并且在(且仅当)将图片的width& height设置为48并将strech设置为none时,我才能使用它:

I have this svg (48x48) and i can use it fine, if (and only if) i set the image's width&height to 48 and the strech to none:

<Image Source="ms-appx:///Assets//check.svg" Height="48" Width="48" Stretch="None"/>

如果我将拉伸设置为填充,则图像消失.如果我增加宽度和高度,我会看到图标固定在图像的左上角(使用不同的svg但大小相同的屏幕截图). Stretch = Fill和固定的高度/宽度不是缩放图像的预期方法吗?

If i set the stretch to fill, the image disappears. If i increase the width and height i can see that the icon is pinned to the upper left corner of the image (screenshot with a different svg but same size). Isn't Stretch=Fill and a fixed height/width the intended way to scale an image?

在我看来,似乎拉伸算法无法理解我的svg应该是48x48.我做错了吗,还是有解决方法?

It looks to my as if the stretching algorithm does not grasp that my svg is supposed to be 48x48. Am i doing it wrong, or are there workarounds?

推荐答案

我整个上午都遇到了同样的问题,并且即将完全放弃对Svg的支持,似乎为无法获得可扩展的格式而发狂正确缩放...

I've been having the same issue all morning and was about to completely give up on Svg support, seems mad that you can't get a scalable format to scale properly...

但是,我又去了一次,我想我已经解决了.

But, I had one more go and I think I've worked this out.

似乎您需要告诉SvgImageSource以SVG的原始设计大小进行栅格化,然后获取Image进行缩放.不确定这是否是一种特别有用的方法,但肯定会在build 15063之前解决它.

It seems that you need to tell the SvgImageSource to rasterize at the SVG's original design size and then get the Image to scale it. Not sure it's a particularly helpful approach, but certainly solves it as of build 15063.

<Image Width="24" Stretch="Uniform" VerticalAlignment="Center">
  <Image.Source>
    <SvgImageSource UriSource="ms-appx:///Assets/salesorder.folder.plain.svg"
                    RasterizePixelHeight="48"
                    RasterizePixelWidth="48" />
  </Image.Source>
</Image>

因此,如果SVG是48x48,我们使用RasterizePixelHeightRasterizePixelWidth值将其转换为48x48的位图,然后图像将其缩放为24x24.

So if the SVG was 48x48 we turn it into a bitmap at 48x48 using the RasterizePixelHeight and RasterizePixelWidth values and then the image scales that to 24x24.

希望有帮助.

更新 我只是重新阅读了您的问题,然后意识到您正在尝试扩大规模,而我一直在努力缩小规模.看起来该技术仍然有效,但是随着位图缩放过程的扩大,您将失去任何图像清晰度.我认为这表明了当前实施中的一个根本缺陷.他们似乎将svg渲染为位图,我们必须告诉它原始大小以使其能够正确渲染,然后允许位图代码完成其余工作.

Update I just re-read your question and realised that you were looking to increase the scale whereas I've been working to decrease it. Looks as though the technique still works, but as you scale up you're going to lose any sharpness of image due to the bitmap scale process. I think this points to a fundamental flaw in the current implementation. They seem to be rendering the svg as a bitmap, and we have to tell it the original size to get it to render properly, and then they allow the bitmap code to do the rest of the work.

我认为这到底是真正的支持还是奇怪的中途辩论,还是有些争议的.某处有人建议Adobe Illustrator可以生成XAML路径,我想我将着眼于此以查看是否可以获得更好的质量输出,但遗憾的是,因为我真的很喜欢Inkscape:-(

I think it's somewhat debateable whether this is true support or an odd half way house. Somewhere someone suggested that Adobe Illustrator can generate XAML paths, I think I'm going to look at that to see whether I can get a better quality output, shame though because I really like Inkscape :-(

这篇关于如何在uwp的xaml中拉伸/调整svg的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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