wmz 文件转为 gif 或 jpg

发布于 2024-09-14 04:20:21 字数 40 浏览 5 评论 0原文

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

How can i convert the "wmz" file to "gif" or "jpg" file in c#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

安穩 2024-09-21 04:20:21

WMZ 是一个压缩的 Windows 图元文件,您可以先解压,然后再解压转换为所需格式(不要忘记处置所有那些 Image 实例(MSDN 示例中未完成)。

WMZ is a compressed Windows Metafile which you could first decompress and then convert to the desired format (don't forget to dispose all those Image instances which is not done in the MSDN example).

扶醉桌前 2024-09-21 04:20:21

感谢您的帮助。我可以解压缩“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;
}

Thanks for the help. I could decompress the "wmz" file and convert it to a wmf file. The code is

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;
}
何处潇湘 2024-09-21 04:20:21

将 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);
    }
}

Convert WMZ to GIF/PNG/JPG/etc:

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文