Comments (1)
Hi George,
I ran into the same issue some time back with checking if a sketch is empty. Here's a link to a SO question with code I used (and I pasted the code below):
http://stackoverflow.com/questions/4735899/how-to-check-if-a-uiimage-is-blank-empty-transparent
I'll look into doing an eraser tool when I get some spare time.
Dave
BOOL isImageBlank(UIImage* image, UIColor* backgroundColor)
{
CGFloat r, g, b, a;
[backgroundColor getRed:&r green:&g blue:&b alpha:&a];
uint8_t red = (uint8_t)(r * 255.0f);
uint8_t green = (uint8_t)(g * 255.0f);
uint8_t blue = (uint8_t)(b * 255.0f);
uint8_t alpha = (uint8_t)(a * 255.0f);
typedef struct {
uint8_t red;
uint8_t green;
uint8_t blue;
uint8_t alpha;
} MyPixel_T;
CGImageRef cgImage = image.CGImage;
//Get a bitmap context for the image
CGContextRef bitmapContext = CGBitmapContextCreate(NULL, CGImageGetWidth(cgImage), CGImageGetHeight(cgImage),
CGImageGetBitsPerComponent(cgImage), CGImageGetBytesPerRow(cgImage),
CGImageGetColorSpace(cgImage), CGImageGetBitmapInfo(cgImage));
//Draw the image into the context
CGContextDrawImage(bitmapContext, CGRectMake(0, 0, CGImageGetWidth(cgImage), CGImageGetHeight(cgImage)), cgImage);
//Get pixel data for the image
MyPixel_T *pixels = CGBitmapContextGetData(bitmapContext);
size_t pixelCount = CGImageGetWidth(cgImage) * CGImageGetHeight(cgImage);
for (size_t i = 0; i < pixelCount; i++) {
MyPixel_T p = pixels[i];
//Your definition of what's blank may differ from mine
if ((p.red != red) || (p.green != green) || (p.blue != blue) || (p.alpha != alpha)) {
return NO;
}
}
return YES;
}
from dascratchpad.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dascratchpad.