2016-10-12 111 views
0

我有下面這段代碼:ZedGraph不配置EMF文件後創建

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#創建

+0

這是什麼原因:http://stackoverflow.com/questions/ 14869578/copyenhmetafile-is-not-releasing-the-handle-even-if-deleteenhmetafile-is-cal – PaulF

+0

可能,但在該鏈接中並沒有說明如何刪除它 –

回答

1

正如我貼的鏈接說 - 你需要刪除由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; 
} 
+0

它的工作原理!答案在上面! :) –