简体   繁体   English

如何将SVG元素的高度/宽度大小转换为像素

[英]How to convert svg element height/width size into pixels

I have some svg elements and I want their height and width in terms of pixels. 我有一些svg元素,我希望它们的高度和宽度以像素为单位。 how to do this? 这个怎么做?

<rect height="200" width="400" fill="red" stroke="1">

Measurements in vector formats are generally relative to the size that the 'window' or 'viewer' that they are going to eventually be rendered in. Without knowing the viewports size in pixels, they are infinitely large or small. 矢量格式的度量通常相对于最终将要呈现的“窗口”或“查看器”的大小。在不知道视口大小(以像素为单位)的情况下,它们的大小无穷大。 If you do have the viweports size and the element isnt being transformed by anything, then you'd need to see where the element is in relation to the viewport, ensure its fully displayed, and then you could calculate its rendered size. 如果确实具有viweports大小,并且元素没有被任何东西变换,那么您需要查看元素相对于视口的位置,确保其完全显示,然后可以计算其渲染的大小。 However, beware if its being clipped out of the diplay by being partially or fully 'off screen'. 但是,请注意其是否被部分或全部“移出屏幕”而被排除在显示之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM