View Full Version : How to compare two UIImage objects?
Sergio10
May 10, 2009, 04:51 PM
Hi,
I have two objects: image1 and image2 with UIImage type.
Need to know are they init with "myImage.png" or not.
How to compare?
Could you please provide the code?
Thanks.
Eraserhead
May 10, 2009, 05:02 PM
You could try hashing, though its an inexact science. I would suggest using NSObject's isEqual: but I guess they won't be the same object, just two objects referencing the same file.
Sergio10
May 10, 2009, 05:31 PM
IsEqual doesn't compare(
I wrote:
UIImage *image1 = [UIImage imageNamed: @"myImage.png"];
UIImage *image2 = [UIImage imageNamed: @"myImage.png"];
if([someImage isEqualTo: patternImage]) // never true (((
{
// some code
}
So, How to know that my UIImage objects initialized with the same image?
Please provide me a code.
Thanks.
Eraserhead
May 10, 2009, 05:39 PM
What research have you already done on this?
You can't just expect free code and that will help round down the location of a solution.
Sergio10
May 10, 2009, 06:03 PM
So,
I suggest to get pixel data(using CGImage) and compare it. How ti do it?
kainjow
May 10, 2009, 06:06 PM
imageNamed: returns a cached object, so for basic purposes you could just try checking the pointers:
if (image1 == image2)
If that doesn't work you could cache the image objects yourself and then compare.
Other than that, you'll have to do some pixel comparisons which won't be pretty.
Sergio10
May 10, 2009, 06:30 PM
So,
I suggest to get pixel data(using CGImage) and compare it. How ti do it?
PhoneyDeveloper
May 10, 2009, 07:41 PM
Forget about comparing pixels.
UImage doesn't keep a name of the file it was inited with. You need to do that part yourself. You could subclass UIImage and add a name property to it. Compare the names to find if they're the same.
Else, you can keep your own dictionary that uses the UIImage* as the key and the name as value. Or keep a couple mutable arrays with UIImages and names as the values.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.