locked
Working with vector images (*.svg) in MS C# 2010 Express ? RRS feed

  • Question

  • Does Microsoft Visual C# 2010 Express provide libraries (or other methods) for working with vector images (*.svg - for instance - for creating svg-viewer) and for rasterize vector images to bitmap format images?
    Sunday, December 23, 2012 2:20 PM

Answers

  • "Does Microsoft Visual C# 2010 Express provide libraries"

    The Metafile class provides methods for Microsoft's vector grahics specification.  The .NET has extensive support for XML which is the basis for svg files.  SVG files can be displayed in IE9 and later.

    Sunday, December 23, 2012 3:13 PM
  • Example how to work with metafiles

    using (var gr = Graphics.FromHwnd(IntPtr.Zero))
    {
        var hdc = gr.GetHdc();
    
        using (var metafile = new Metafile("Sample.emf", hdc))
        using (var g = Graphics.FromImage(metafile))
        {
            // something draw
            g.DrawRectangle(Pens.Blue, 0, 0, 100, 50);
            g.FillEllipse(Brushes.Yellow, 10, 10, 80, 30);
            g.DrawString("Hello World!", Font, Brushes.Red, 0, 0);
        }
    
        gr.ReleaseHdc(hdc);
    }

    In managed code we must to use GetHdc and ReleaseHdc that messed our code.

    • Proposed as answer by HappyAmy Tuesday, December 25, 2012 5:46 AM
    • Marked as answer by Lisa ZhuModerator Monday, December 31, 2012 5:44 AM
    Sunday, December 23, 2012 9:19 PM

All replies

  • "Does Microsoft Visual C# 2010 Express provide libraries"

    The Metafile class provides methods for Microsoft's vector grahics specification.  The .NET has extensive support for XML which is the basis for svg files.  SVG files can be displayed in IE9 and later.

    Sunday, December 23, 2012 3:13 PM
  • Thank JohnWein - I just now see this method... but I heard that working with vector images in studio's is a full headache - for instance, vector images viewing and rasterize to bmp-format in Qt (or in MS C++ with QT Add-in) involve only 6 code strings.

    Sunday, December 23, 2012 4:29 PM
  • Example how to work with metafiles

    using (var gr = Graphics.FromHwnd(IntPtr.Zero))
    {
        var hdc = gr.GetHdc();
    
        using (var metafile = new Metafile("Sample.emf", hdc))
        using (var g = Graphics.FromImage(metafile))
        {
            // something draw
            g.DrawRectangle(Pens.Blue, 0, 0, 100, 50);
            g.FillEllipse(Brushes.Yellow, 10, 10, 80, 30);
            g.DrawString("Hello World!", Font, Brushes.Red, 0, 0);
        }
    
        gr.ReleaseHdc(hdc);
    }

    In managed code we must to use GetHdc and ReleaseHdc that messed our code.

    • Proposed as answer by HappyAmy Tuesday, December 25, 2012 5:46 AM
    • Marked as answer by Lisa ZhuModerator Monday, December 31, 2012 5:44 AM
    Sunday, December 23, 2012 9:19 PM
  • Hi JohnWein - thank for your information, but... may be you can help me also one :) So I start to work with System.Xml Library (.NET Libraries) and did to reading svg-file already. But I can't to find any Method (in this library) which to help me convert strings of reading svg to pixel massive ( for convert to rasterize image like PNG or JPG) :( Can you advice something for this ??? Anyway - thank you :)
    Friday, December 28, 2012 4:28 AM
  • Hi JohnWein - thank for your information, but... may be you can help me also one :) So I start to work with System.Xml Library (.NET Libraries) and did to reading svg-file already. But I can't to find any Method (in this library) which to help me convert strings of reading svg to pixel massive ( for convert to rasterize image like PNG or JPG) :( Can you advice something for this ??? Anyway - thank you :)
    PNG and JPG are file containers for compressed images.  Use Image.Save(FileName, ImageFormat.Png) or Image.Save(FileName, ImageFormat.Jpeg) to save your images.
    Friday, December 28, 2012 4:35 AM