Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two UIImage objects

Tags:

ios

I am developing one application.In that i am using the imageviews.SO before changeing the UIImageview image I need to take that image in UIimage obejct and compare with another UIImage object for finding both are sam or not. So please tell me how to do that one.

like image 989
user1498119 Avatar asked Jul 05 '12 10:07

user1498119


People also ask

How to compare UIImage in swift?

Swift. // Load the same image twice. let image1 = UIImage(named: "MyImage") let image2 = UIImage(named: "MyImage") // The image objects may be different, but the contents are still equal if let image1 = image1, image1. isEqual(image2) { // Correct.

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

What is UIImage Swift?

An object that manages image data in your app.


1 Answers

One way is to convert them to image data first, and then compare that.

- (BOOL)image:(UIImage *)image1 isEqualTo:(UIImage *)image2 {     NSData *data1 = UIImagePNGRepresentation(image1);     NSData *data2 = UIImagePNGRepresentation(image2);      return [data1 isEqual:data2]; } 
like image 121
Simon Avatar answered Sep 22 '22 20:09

Simon