0
創建SVG圖像時,必須設置寬度,高度和位置,否則將不會呈現。 如何從原始圖像中讀取它們? 使用Dart我首先加載html圖像,並在加載後得到大小,然後定義SVG圖像並使用之前獲得的信息。這有點麻煩,我想知道是否有另一種方式。定義SVG圖像正確大小的最佳方法
鏢代碼如下所示:
ImageElement img = new ImageElement(src:'2.jpg'); //401x600
img.onLoad.listen((e) {
svg.ImageElement image = new svg.ImageElement();
image.setAttribute('x', '0');
image.setAttribute('y', '0');
image.setAttribute('width', img.width.toString());
image.setAttribute('height', img.height.toString());
image.getNamespacedAttributes('http://www.w3.org/1999/xlink')['href'] = '2.jpg';
});