Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG to PNG: not all SVG elements are converting #144

Closed
Jagailo opened this issue Mar 5, 2023 · 3 comments
Closed

SVG to PNG: not all SVG elements are converting #144

Jagailo opened this issue Mar 5, 2023 · 3 comments

Comments

@Jagailo
Copy link

Jagailo commented Mar 5, 2023

Hello.
I need to convert svg image to png, but the result is different from what I see in Chrome.

Left svg image in Chrome, right png image after conversion:
1-deff
2-diff

Code:

using SkiaSharp;
using Svg.Skia;

const string input = @"C:\Users\Username\Desktop\1.svg";
const string output = @"C:\Users\Username\Desktop\1.png";

var svg = new SKSvg();
svg.Load(input);

var stream = new MemoryStream();

svg.Picture?.ToImage(stream: stream,
    background: SKColors.Empty,
    format: SKEncodedImageFormat.Png,
    quality: 90,
    scaleX: 1f,
    scaleY: 1f,
    skColorType: SKImageInfo.PlatformColorType,
    skAlphaType: SKAlphaType.Unpremul,
    skColorSpace: SKColorSpace.CreateRgb(SKColorSpaceTransferFn.Srgb, SKColorSpaceXyz.Srgb));

stream.Seek(0, SeekOrigin.Begin);

using var fileStream = File.Create(output);
stream.CopyTo(fileStream);

Packages:

  • SkiaSharp 2.88.3
  • SkiaSharp.NativeAssets.Linux.NoDependencies 2.88.3
  • Svg.Skia 0.5.18

SVG images: images.zip

Any suggestions for code? Or maybe the svg images are bad? Or is it really a bug?
Thanks

@NexDrill
Copy link

NexDrill commented Mar 6, 2023

This has nothing to do with the Svg.Skia. I believe the parts "missing" in each of the files are not showing because they are not svg. In the first image what would be the aorta is basically an embedded image in the file. So because it is not svg the Package is unable to process it.

I recommend you screenshot the images, then use something like inkscape to trace them out to true svg's.

Hope this helps.

@Jagailo
Copy link
Author

Jagailo commented Mar 6, 2023

Thanks for the answer. Since this has nothing to do with the library, the issue can be closed.

@Jagailo
Copy link
Author

Jagailo commented Mar 6, 2023

Do you have any ideas how to convert these schemes to images via C# code?
(except using the engine Chromium for rendering)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants