首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >当我在zip文件中重命名文件时,KMZ只显示图标文件。

当我在zip文件中重命名文件时,KMZ只显示图标文件。
EN

Stack Overflow用户
提问于 2014-03-20 23:48:47
回答 1查看 734关注 0票数 2

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

我的尝试:

  1. 在Google中打开KMZ文件之后,图标就会显示出来。
  2. 然后,我将KMZ转换成一个zip文件,以便检查它的内容。
  3. 我将图标重命名为不同的名称,然后返回到它的原始名称。
  4. 然后,我将其更改为KMZ文件,并在Google中打开,图标显示得很好。

对于我在压缩过程中做错了什么会导致图标一开始不显示有什么想法吗?

EN

Stack Overflow用户

回答已采纳

发布于 2014-03-26 13:21:33

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

若要使KMZ文件在Google和其他地球浏览器中可互操作,则必须使用“遗留”压缩方法(例如压缩)与ZIP2.0兼容,而不使用扩展(如Zip64 )。KML Errata中提到了这个问题。

下面是创建KMZ文件的C#代码片段:

代码语言:javascript
复制
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();
    }
}
票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22547522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档