wmz文件到gif或jpg

时间:2010-08-16 09:10:01

标签: c# gif jpeg

如何在c#中将“wmz”文件转换为“gif”或“jpg”文件?

3 个答案:

答案 0 :(得分:2)

WMZcompressed Windows Metafile,您可以先解压缩然后convert to the desired format(不要忘记处理MSDN示例中未完成的所有Image个实例)。

答案 1 :(得分:1)

感谢您的帮助。我可以解压缩“wmz”文件并将其转换为wmf文件。代码是

public String DeCompressWMZFile(String wmzFile)
{
    MemoryStream decompressStream = new MemoryStream(File.ReadAllBytes(wmzFile));
    GZipStream gzipStream = new GZipStream(decompressStream, CompressionMode.Decompress);
    MemoryStream outStream = new MemoryStream();
    int readCount;
    byte[] data = new byte[2048];
    do
    {
        readCount = gzipStream.Read(data, 0, data.Length);
        outStream.Write(data, 0, readCount);
    } while (readCount == 2048);
    String imgFile = Path.GetDirectoryName(wmzFile) + "\\" + Path.GetFileNameWithoutExtension(wmzFile) + ".wmf";
    File.WriteAllBytes(imgFile, outStream.GetBuffer());
    // Then add the code to create a new word document and insert 
    return imgFile;
}

答案 2 :(得分:0)

将WMZ转换为GIF / PNG / JPG /等:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://link1.ru/image.wmz");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream inputStream = response.GetResponseStream()) 
{
    using (GZipStream gzipStream = new GZipStream(inputStream, CompressionMode.Decompress))
    {
        Image i = Image.FromStream(gzipStream);
        i.Save("1.gif", ImageFormat.Gif);
    }
}