开发者

How can I compare images in a PictureBox and an ImageList?

I am using an ImageList and a PictureBox in my application. I am loading the image in the PictureBox dynamically from an image in the ImageList. I need to check whether the image in the PictureBox and a certain index of an image in the ImageList are equal. Can an开发者_Python百科yone guide me?


Unfortunately, the Image class doesn't implement the == operator or the Equals method, which means it inherits the default implementation from the Object class that simply checks if the object references are the same. It turns out that this will fail, even if an image is assigned to the PictureBox directly out of your ImageList.

So, you'll need to implement your own logic to check if the images are the same. There are a couple of different approaches. You could either load each of the two images into a byte array and do a byte-by-byte comparison, or you could loop through the two images pixel-by-pixel and compare their colors. Of course, both of these methods are going to be anywhere from relatively to unreasonably slow. You could potentially optimize either by simply comparing the dimensions first (the Image object does provide a Size property that returns its dimensions) and returning False if they are not equal, but this probably won't work in your case, since all of the images in the ImageList will have the same dimensions.

If it were me, I'd save myself the trouble and just keep the index of the image in the ImageList that I assigned to the PictureBox somewhere in a class-level variable...

If you're still resolute despite my warnings, see the answers to this similar question.


Dude instead of going for a image list. just go with the list box. I have a programmed a tool in C# wherein it takes 2 inputs from user. First being the folder which contains bulk of images and second being the input image ( whose similar images u need to separate from the bulk of images.

  1. when to take the input folder. List out the contents of the folder in the listBox i.e; the path of every image in the folder.

  2. now since you have the path of every image in the folder, take images one by one into a Image for Bitmap and compare it with the input image you have given earlier. Use any methods or similarity metric to find out to what extent or what % the images are same.

  3. Note the %'s and then separate them from the bulk of images.( this is again easy since you have the path of every image in the folder.)

I don't know to what extent i made myself clear. I hope this was of some help to you. good luck


There is absolute solution

Assign a value to image.

Tag differently for each image

That's the solution then you can compare based on tag value

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜