TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kasun Lee
NA
178
14.4k
Finding dupicated images
Sep 23 2019 1:29 AM
Hi!
I have this picture folder, which has duplicated image files. I wanna get rid of the duplicates, so to identify those images, I wrote below disfunctional, amature piece of code. I was trying to insert width, height, and size of all images into Lists, and then enumarate each image again, comparing the W, H, SZ values to the previously stored values. If two images have the same w, h, sz values, I'll know they are duplicates. Can anyone please either show me how to fix the code, OR show me a Different approch to it that's simpler than this?
private
void
recheckForDuplicatesToolStripMenuItem_Click(
object
sender, EventArgs e)
{
string
src = Path.GetDirectoryName(Application.ExecutablePath) +
"\\Pics"
;
string
[] srcfiles = Directory.GetFiles(src);
int
n = 0;
List<
int
> imgH =
new
List<
int
>();
List<
int
> imgW =
new
List<
int
>();
List<
long
> imgSz =
new
List<
long
>();
foreach
(
string
srcfile
in
srcfiles)
{
try
{
Image img = Image.FromFile(srcfile);
imgH.Add(img.Height);
imgW.Add(img.Width);
long
len = (
new
FileInfo(srcfile)).Length;
imgSz.Add(len);
img.Dispose();
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
int
x = 0;
foreach
(
string
srcfile
in
srcfiles)
{
Image img = Image.FromFile(srcfile);
long
len = (
new
FileInfo(srcfile)).Length;
for
(
int
z = 0; z < imgH.Count; z++)
{
if
(imgH[z] == img.Height && imgW[z] == img.Width && imgSz[z] == len)
{
if
(x == z)
{
continue
;
}
x++;
if
(n >= 2)
{
//MessageBox.Show("Possible Duplicate: \n" + srcfile + "\n" +
// img.Height + " " + img.Width + " " + len);
n = 0;
}
n++;
}
}
x = 0;
img.Dispose();
}
}
THANKS!!
Reply
Answers (
4
)
service references and web references
Redialling if call did not answer Twilio.