【发布时间】:2014-06-17 18:20:33
【问题描述】:
我想创建一个应用程序来删除某个文件夹中的重复照片,所以我需要将图像转换为 ARGB 数组 [one diemnsion] 然后比较它们。 将图像转换为 ARGB 数组的最快方法是什么? 或者如何改进这段代码?
Image img;
using (FileStream stream = new FileStream(imagefile, FileMode.Open))
{
img = Image.FromStream(stream);
}
using (Bitmap bmp = new Bitmap(img))
{
int[] argb = new int[bmp.Width * bmp.Height];
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color pxl = bmp.GetPixel(x, y);
argb[x * y] = pxl.ToArgb();
}
}
}
【问题讨论】:
-
您将希望使用 LockBits() 来锁定内存中的整个区域,而不是 GetPixel(),后者的效率相对较低。
-
怎么做,请给我一个例子
-
Bitmap 类的 MSDN 文档中提供了示例。
-
如果您要比较文件是否完全重复,可以使用散列函数(参见此处:stackoverflow.com/questions/10520048/…)