question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set x/y position for SVG draw

See original GitHub issue

Description

The SVG graphic is always positioned at point 0, 0. The transfer of the values is ignored when drawing. The assigned values (e.g. x = 25; y = 125) are not transferred to the SVG object.

In version 3.0.102 the values were taken over correctly and the SVG graphics were positioned. In this version Integer values could be used directly. The conversion to Single and then to SvgUnit was an attempt to adapt it to the new version. Unfortunately, this failed.

Example data

Dim recoloredSVG As SvgDocument = SvgDocument.Open(DocSVG.BaseUri.LocalPath)
Dim x As Integer = 25
Dim y as Integer = 125
Dim x As Single = Convert.ToSingle(x_icon)
Dim y As Single = Convert.ToSingle(y_icon)

Dim svg_x As SvgUnit = New SvgUnit(SvgUnitType.Pixel, x)
Dim svg_y As SvgUnit = New SvgUnit(SvgUnitType.Pixel, y)

With recoloredSVG
	.Width = w_icon
	.Height = h_icon
	.X = svg_x
	.Y = svg_y
	.Draw(e.Graphics)
End With

Used Versions

Nuget Version 3.3.0 .NET Framework 4.8 OS Win 10 21H1 (Build 19043.1288)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Ischtasucommented, Oct 20, 2021

Took a little longer but I can confirm that it works.

2reactions
faiithcommented, Oct 16, 2021

Tried the workaround using TranslateTransform, seems to work 😃

My approach …

` Dim vektorgrafik As Svg.SvgDocument = design.gfx.vector.wagen.byKey(name)

    Dim bild As New Bitmap(sizeX, sizeY)

    Dim sX, sY As Integer
    sX = 30
    sY = 30

    Dim svgX As Single, svgY As Single

    svgX = CSng((sizeX - sX) / 2)
    svgY = CSng((sizeY - sY) / 2)

    Using gr As Graphics = Graphics.FromImage(bild)
        gr.FillRectangle(design.pinsel.solid.Form.backcolor, bild.GetBounds(GraphicsUnit.Pixel))
        If Not IsNothing(vektorgrafik) Then
            With vektorgrafik
                .Width = sX
                .Height = sY
                Using renderer As Svg.ISvgRenderer = Svg.SvgRenderer.FromGraphics(gr)
                    renderer.TranslateTransform(svgX, svgY)
                    .Draw(renderer)
                End Using
            End With
        End If
    End Using
    Return bild`
Read more comments on GitHub >

github_iconTop Results From Across the Web

Set X and Y value for g element of SVG
I am relatively new in SVG drawing with HTML5. What I want to do is to make a group of elements in SVG...
Read more >
Positions - SVG: Scalable Vector Graphics - MDN Web Docs
In this article, we examine how Scalable Vector Graphics (SVG) represents the positions and sizes of objects within a drawing context, ...
Read more >
Coordinate Systems, Transformations and Units — SVG 2
Every SVG viewport defines a drawing region characterized by a size (width, height), and an origin ... set the larger of scale-x and...
Read more >
SVG Coordinate Systems and Units - SVG Viewport and ...
Let's examine how SVG represents the positions and sizes of objects for drawing. The default coordinate system in SVG is much the same...
Read more >
Mimic Relative Positioning Inside an SVG with Nested SVGs
Every element in SVG is positioned "absolutely" relative to the SVG viewport, and the position inside the viewport is governed by the current ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found