分别转化为NSData,对比是否相等
-
(BOOL)imageEqualToImage:(UIImage *)image anotherImage:(UIImage *)anotherImage {
NSData *orginalData = UIImagePNGRepresentation(image);
NSData *anotherData = UIImagePNGRepresentation(anotherImage);
if ([orginalData isEqual:anotherData]) {
return YES;
}
return NO;
}
设置图片透明度
-
(UIImage )imageByApplyingAlpha:(CGFloat)alpha image:(UIImage)image {
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0f);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextSetAlpha(ctx, alpha);
CGContextDrawImage(ctx, area, image.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}