比较 UIImage [英] Comparing UIImage

查看:17
本文介绍了比较 UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一张图片与另一张图片进行比较?

How can I compare an image to another one?

谢谢!

推荐答案

如果您有两个 UIImage,您应该从这些对象中获取它们的 CGImageRef 石英表示.然后创建两个由您创建并传入的内存缓冲区支持的新位图上下文,每个图像一个.然后使用 CGContextDrawImage 将图像绘制到位图上下文中.现在图像的字节在缓冲区中.然后您可以手动或 memcmp 循环以检查差异.

If you have two UIImages, you should get their CGImageRef quartz representations from those objects. Then create two new bitmap contexts backed by a memory buffer that you create and pass in, one for each of the images. Then use CGContextDrawImage to draw the images into the bitmap contexts. Now the bytes of the images are in the buffers. You can then loop through manually or memcmp to check for differences.

Apple 自己关于创建位图上下文并绘制到其中的详细说明和示例代码在这里:

Apple's own detailed explanation and sample code around creating bitmap contexts and drawing into them is here:

https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html

对您而言,不同之处在于您将现有图像绘制到上下文中.为此使用 CGContextDrawImage.

The difference for you is that you're drawing an existing image into the context. Use CGContextDrawImage for this.

这篇关于比较 UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆