0

我有包含 SVG 图像的 XML 文件。这些图像是用 base64 编码的,并且可能是 gzip 压缩的(根据制造商的说法)。

内容是这样的

<Image ID="ID_IMG57" ElementID="ID_IMG57" PMD="svg" X="1281" Y="370" ZIndex="-2" 
      W="36" H="56" MirrorX="False" MirrorY="False" Angle="0" ViewID="" Locked="False" 
      PlacementAngle="-360" PlacementX="1" PlacementY="27" PlacementScale="0" 
      Format="image/svg+base64" IncludeRelevantModules="True">
   <ImageValue>7b0HYBxJliUmL23Ke39K9UrX4HShCIBgEyTYkEAQ7MGIzeaS7B1pRyMpqyqBymVWZV1mFkDM7Z28995777333nvvvfe6O51OJ/ff/z9cZmQBbPbOStrJniGAqsgfP358Hz8iHjeXF2l6WeRXT6p3n320vTvevb+7d+9hur33YLz74MH9g/Te/fEBPkvv3x8/eLj36d5H6VUxa+effbS7s/O7f5TO8+Ji3pq/3i3KZfPZR/O2XT26e/fq6mp8dW9c1Rd393Z2du5Sbx8dPV43eZpOy6yhhpPVSl969K4slm9jr+4+fPjwLn9LTfHj0bzOzz/7iP767KOd8d4e4fzpR+k14b8zvndw/+Dhg4/Su0ePqSl19G4XjXb39u8dUBv6Y3vvUxkavb/H78iY6Vv6c+/+eOfT+/u7H6VNe13mn33UtHX1Nn/04zv8HKby9zbT4NHuYXpelOWjZbXMDz8K+twb7+083Lu3q53uPhjfu0cdSae7u+P7e/t7B9Kn9+XX6nRVldfS8aoqli2R9R5N1ac0baPt3YPx/t7Op/dS6nH33u6DhyP0tn9vZ28/vTf+FGP9lD76lD56ePDp10TAjXp3fEA88uk9GTWBfbC78+mndtB7Ow8e7Mmg3Xdfq8vYmO8TEe/tj3bvjz+9f49Yl/rbf7j/6e6I+vqUxveARnyPqL53MCIafHpv/979r9l7m79rU7AfjZc4afchs98eU3GnB5RfEwgW/nm1bLeb4gf5o/3VO/3zPFsU5fWj47rIysMUfWxny+m8qh81bVa3hx8dPSmL6du6mM7b9fLi8V008ZA5GD+8d+/TfRGF3Yfj3V3m8vdCZn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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   </ImageValue>
   <ImageAttributes>
       <ImageAttribute Name="FileNameSVG" Value="Blickrichtung1.svg" Source="User" />
   </ImageAttributes>
</Image>

实际的图像在ImageValue元素中。但我无法将其提取出来。我试过

byte[] compressed = Convert.FromBase64String(image.Value);
using (GZipStream stream = new GZipStream(new MemoryStream(compressed),
                                                     CompressionMode.Decompress))
{
     const int size = 4096;
     byte[] buffer = new byte[size];
     using (MemoryStream memory = new MemoryStream())  {
         int count = 0;
         do {
             count = stream.Read(buffer, 0, size);
             if (count > 0) {
                 memory.Write(buffer, 0, count);
             }
         }
         while (count > 0)
         File.WriteAllBytes(@"Blickrichtung1.svg", memory.ToArray());
     }
}

但图像不显示任何内容。我如何确定这背后的格式?

我还尝试了仅 base64 解码并将数据保存到文件中。我希望我能在二进制文件中看到文件类型之类的东西,但没有运气。

4

1 回答 1

1

就像@BigBadaboom 怀疑的那样,它是一个泄气的流。以下在svg.

    string svg;
    using (var stream = new DeflateStream(new MemoryStream(compressed),  
        CompressionMode.Decompress))
    {
        using (MemoryStream memory = new MemoryStream())
        {
            stream.CopyTo(memory);
            byte[] decompressed = memory.GetBuffer();
            svg = Encoding.UTF8.GetString(decompressed);  
        }     
    }
于 2013-11-01T17:20:57.530 回答