我正在尝试使用此包装器https://github.com/ludoviclefevre/phash-integration-in-csharp
来使用phash库c ++标题:
int ph_dct_imagehash(const char* file,ulong64 &hash)
c#dll import:
DllImport(@"pHash.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int ph_dct_imagehash(string file, ref ulong hash);
测试代码:
ulong hash = 0;
foreach (var file in files)
{
ph_dct_imagehash(file, ref hash);
dictionary.Add(file, hash);
}
它适用于少数图片,但当大约200-300张图片时,我获得了Accesviolation异常
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
我的第一个主要是垃圾收集器,但我很困惑..我应该使用intpr而不是字符串和哈希参数?我尝试将ref参数更改为out但不重要..