如何比较 PictureBox 和 ImageList 中的图像?

发布于 2024-10-08 13:35:34 字数 216 浏览 7 评论 0原文

我在我的应用程序中使用 ImageListPictureBox 。我正在从 ImageList 中的图像动态加载 PictureBox 中的图像。我需要检查 PictureBox 中的图像和 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 anyone guide me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

擦肩而过的背影 2024-10-15 13:35:35

伙计,而不是去寻找图像列表。只需使用列表框即可。
我用 C# 编写了一个工具,其中需要用户的 2 个输入。第一个是包含大量图像的文件夹,第二个是输入图像(您需要将其相似图像与大量图像分开。

  1. 何时获取输入
    文件夹。列出其中的内容
    列表框中的文件夹即;这
    文件夹中每个图像的路径。

  2. 现在既然你有了路径
    文件夹中的每个图像,取
    图像一张一张地变成一个Image
    位图并将其与输入进行比较
    您之前给出的图像。使用
    任何方法或相似性度量
    找出什么程度或什么%
    图像是相同的。

  3. 注意 %,然后
    将它们与大部分分开
    图像。(这又很容易,因为
    你有每个图像的路径
    文件夹。)

我不知道我在多大程度上说清楚了。我希望这对你有一些帮助。祝你好运

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

最舍不得你 2024-10-15 13:35:35

有绝对的解决方案

为图像分配一个值。

为每个图像添加不同的标签

这就是解决方案,然后您可以根据标签值进行比较

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

我喜欢麦丽素 2024-10-15 13:35:34

不幸的是,Image 类没有实现 == 运算符或 Equals 方法,这意味着它继承了 Image 类的默认实现。 >Object 类,仅检查对象引用是否相同。事实证明,即使直接从 ImageList 中将图像分配给 PictureBox,这也会失败。

因此,您需要实现自己的逻辑来检查图像是否相同。有几种不同的方法。您可以将两个图像中的每一个加载到字节数组中并进行逐字节比较,或者可以逐像素循环遍历两个图像并比较它们的颜色。当然,这两种方法的速度都会相对缓慢到不合理。您可以通过简单地首先比较尺寸来优化其中一个(Image 对象确实提供了 Size 属性 返回其尺寸),如果它们不相等则返回 False,但这可能不适用于您的情况,因为 ImageList 中的所有图像都具有相同的尺寸。

如果是我,我会省去自己的麻烦,只需将分配给 PictureBoxImageList 中的图像索引保留在类级变量中的某个位置即可...

如果尽管我的警告您仍然坚决,请参阅 这个类似的问题

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文