I am using PHASH for computing the hash values for a large database of images. These images are of high resolution and hence I need to resize them for fast computing of the hash.
However, when I resize the image, the PHASH program throws an error. If I don't resize, the PHASH program works fine.
My resize code is as below.
public void ResizeImage(string ImagePath, int width, int height, string newPath)
{
Bitmap b = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage((Image)b))
{
FileStream fs = new FileStream(ImagePath, FileMode.Open);
Image img = Image.FromStream(fs);
g.DrawImage(img, 0, 0, width, height);
fs.Close();
}
b.Save(newPath);
b.Dispose();
}
The error which I receive is "Attempted to read or write protected memory".
The phash code is as below:
ph_dct_imagehash(imagePath, ref hash);
The above function calls the C++ program and returns me the hash value for that image. It works fine when the image is not resized programmatically. If I resize the image using MS Paint then also it works fine.