which is the best way to check whether a UIImage is blank?
I have this painting editor which returns a UIImage; I don\'t want to save this imag
Here's a solution in Swift that does not require any additional frameworks.
Thanks to answers in a related question here: Get Pixel Data of ImageView from coordinates of touch screen on xcode?
func imageIsEmpty(_ image: UIImage) -> Bool {
guard let cgImage = image.cgImage,
let dataProvider = cgImage.dataProvider else
{
return true
}
let pixelData = dataProvider.data
let data: UnsafePointer = CFDataGetBytePtr(pixelData)
let imageWidth = Int(image.size.width)
let imageHeight = Int(image.size.height)
for x in 0..