【问题标题】:KMZ only shows Icon file when I rename file in the zip file当我在 zip 文件中重命名文件时,KMZ 仅显示图标文件
【发布时间】:2014-03-20 23:48:47
【问题描述】:

我正在使用http://www.icsharpcode.net/opensource/sharpziplib/ 编写一个 C# 程序 将包含 KML 文件和图标的 KMZ 文件压缩为 zip 文件。

我的尝试:

  1. 在 Google 地球中打开 KMZ 文件后,现在会显示图标。
  2. 然后我将 KMZ 转换为 zip 文件,以便检查其内容。
  3. 我将图标重命名为不同的名称,然后恢复为原来的名称。
  4. 然后我将其改回 KMZ 文件并在 Google 地球中打开,图标显示正常。

关于我在压缩过程中做错了什么会导致图标最初不显示的任何想法?

【问题讨论】:

  • 可能想详细说明 KMZ 如何“转换”为 ZIP 文件,因为 KMZ 已经是 .ZIP 但具有不同的扩展名。假设您只是重命名文件扩展名(即 .kmz 到 .zip)。如果您使用 WinZip 重命名图标,则它可能会重置条目上的某些属性和/或在保存时清除其他标题信息,以便生成的文件有效。如何创建 KMZ 的代码片段会有所帮助。

标签: icons kml kmz


【解决方案1】:

让使用CSharpZipLib 创建的 KMZ 文件与 Google 地球正常工作的一个技巧是关闭与 Google 地球不兼容的 Zip64 模式。

要使 KMZ 文件在 Google 地球和其他地球浏览器中可互操作,它必须使用“传统”压缩方法(例如 deflate)与 ZIP 2.0 兼容,并且不能使用 Zip64 等扩展名。 KML Errata中提到了这个问题。

这里是创建 KMZ 文件的 C# 代码的 sn-p:

using (FileStream fileStream = File.Create(ZipFilePath)) // Zip File Path (String Type)
{
    using (ZipOutputStream zipOutputStream = new ZipOutputStream(fileStream))
    {
        // following line must be present for KMZ file to work in Google Earth
        zipOutputStream.UseZip64 = UseZip64.Off;

        // now normally create the zip file as you normally would 
        // add root KML as first entry
        ZipEntry zipEntry = new ZipEntry("doc.kml");
        zipOutputStream.PutNextEntry(zipEntry);  
        //build you binary array from FileSystem or from memory... 
        zipOutputStream.write(/*binary array*/); 
        zipOutputStream.CloseEntry();
        // next add referenced file entries (e.g. icons, etc.)
        // ...
        //don't forget to clean your resources and finish the outputStream
        zipOutputStream.Finish();
        zipOutputStream.Close();
    }
}

【讨论】:

  • 我已将其关闭,但当图标位于 zip 文件的目录中时,仍然有同样的问题。但是,当图标文件不在目录中时,它们会显示得很好。不确定当图像位于 zip 文件的目录中时这不起作用,为什么这不起作用
  • 在对图标条目调用 PutNextEntry() 之前尝试手动设置条目的文件大小;例如newEntry.Size = .
猜你喜欢
  • 2016-05-19
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
  • 2013-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多