1

I am converting svg image to png format. I am getting image from url. I am getting exception Parameter is not valid. Following is my code:

string svgFileName = "https://upload.wikimedia.org/wikipedia/commons/e/ed/Chicago_Cubs_Logo.svg";
using (WebClient webClient = new WebClient())
{
    byte[] data = webClient.DownloadData(svgFileName);

    ImageConverter imageConverter = new System.Drawing.ImageConverter();
    Image image = imageConverter.ConvertFrom(data) as Image;
    image.Save("c:\\hello", ImageFormat.Png);                    
}

I am getting the following exception:

enter image description here

Following is my StackTrace:

at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)   
at System.ComponentModel.TypeConverter.ConvertFrom(Object value)

What am I missing?

halfer
  • 19,824
  • 17
  • 99
  • 186
Nimit Joshi
  • 1,026
  • 3
  • 19
  • 46

1 Answers1

3

SVG is file not a plain image, you need to download svg as a file not a image.

string svgFileName = "https://upload.wikimedia.org/wikipedia/commons/e/ed/Chicago_Cubs_Logo.svg";
using (WebClient webClient = new WebClient())
{
   webClient.DownloadFile(svgFileName, "hello.svg");             
}

Once you download the file you need to convert this svg file into image, for that you can use SVG Nuget Gallery.

you can visit this links for svg file conversion. https://stackoverflow.com/a/58912/2745294 https://stackoverflow.com/a/12884409/2745294

Sushil Mate
  • 583
  • 6
  • 14
  • 1
    Thanks a lot. I am stretching my head from last two hours. I just added the code from the links you have provided. – Nimit Joshi Jul 05 '17 at 07:12