ZedGraph 在创建 emf 文件后不处理它

ZedGraph doesn't dispose emf file after create it

我有以下代码:

static internal bool SaveEnhMetafileToFile(Metafile mf, string fileName)
{
  bool bResult = false;
    IntPtr hEMF;
    hEMF = mf.GetHenhmetafile(); // invalidates mf 
    if (!hEMF.Equals(new IntPtr(0)))
    {
        StringBuilder tempName = new StringBuilder(fileName);
        CopyEnhMetaFile(hEMF, tempName);
        DeleteEnhMetaFile(hEMF);

   }
    return bResult;
}

调用CopyEnhMetaFile(hEMF, tempName);时,创建了图片,但在调用DeleteEnhMetaFile(hEMF);函数后,我无法删除图片,因为我的程序正在使用它(vshost.exe)。 该程序是用 C# 创建的

如我发布的 link 中所述 - 您需要删除由 CopyEnhMetaFile 创建的句柄:

static internal bool SaveEnhMetafileToFile(Metafile mf, string fileName)
{
  bool bResult = false;
  IntPtr hEMF;
  hEMF = mf.GetHenhmetafile(); // invalidates mf 
  if (!hEMF.Equals(new IntPtr(0)))
  {
    StringBuilder tempName = new StringBuilder(fileName);
    IntPtr hCopyEMF = CopyEnhMetaFile(hEMF, tempName.ToString());
    DeleteEnhMetaFile(hCopyEMF);
    DeleteEnhMetaFile(hEMF);
  }
return bResult;
}