Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sergio10

macrumors regular
Original poster
Oct 3, 2007
137
0
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.
 
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.
 
IsEqual doesn't compare(
I wrote:
PHP:
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.
 
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.
 
So,

I suggest to get pixel data(using CGImage) and compare it. How ti do it?
 
imageNamed: returns a cached object, so for basic purposes you could just try checking the pointers:
Code:
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.
 
So,

I suggest to get pixel data(using CGImage) and compare it. How ti do it?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.