mirror of
https://github.com/hyperoslo/Cache.git
synced 2026-04-07 19:17:36 +00:00
29 lines
638 B
Swift
29 lines
638 B
Swift
#if canImport(UIKit)
|
|
import UIKit
|
|
|
|
extension UIImage {
|
|
func isEqualToImage(_ image: UIImage) -> Bool {
|
|
let data = normalizedData()
|
|
return data == image.normalizedData()
|
|
}
|
|
|
|
func normalizedData() -> Data {
|
|
let pixelSize = CGSize(
|
|
width : size.width * scale,
|
|
height : size.height * scale
|
|
)
|
|
|
|
UIGraphicsBeginImageContext(pixelSize)
|
|
draw(
|
|
in: CGRect(x: 0, y: 0, width: pixelSize.width,
|
|
height: pixelSize.height)
|
|
)
|
|
|
|
let drawnImage = UIGraphicsGetImageFromCurrentImageContext()
|
|
UIGraphicsEndImageContext()
|
|
|
|
return drawnImage!.cgImage!.dataProvider!.data! as Data
|
|
}
|
|
}
|
|
#endif
|