SVGProcessor.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Triplet_Loss_SBIR 作者: TuBui 项目源码 文件源码
def get_numpy_array(self, size=256, scale=0.333):
        """
        using rsvg library, render the svg into a cairo surface with memory
        defined by a numpy array, effectively rendering the svg to an array
        """
        if self.tree_root is None:
          self.tree_root = self.tree_org.getroot()

        # get the result into a svg object (using rsvg lib)
        svg_object = rsvg.Handle(ET.tostring(self.tree_root))

        # create a numpy array to use as our canvas
        data = np.zeros((size, size, 4), dtype=np.uint8)
        surface = cairo.ImageSurface.create_for_data(
            data, cairo.FORMAT_ARGB32, size, size)

        cr = cairo.Context(surface)

        # fill with solid white and set scale (magic scale number)
        cr.set_source_rgb(1.0, 1.0, 1.0)
        cr.paint()
        cr.scale(scale, scale)

        # render our manipulated svg into cairo surface
        svg_object.render_cairo(cr)

        return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号