This isn't what you probably thought it was to begin with. I know how to use UIImage's, but I now need to know how to create a "blank" UIImage using:
CGRect screenRect = [self.view bounds];
You need to use
CoreGraphics, as follows.
CGSize size = CGSizeMake(desiredWidth, desiredHeight); UIGraphicsBeginImageContextWithOptions(size, YES, 0); [[UIColor whiteColor] setFill]; UIRectFill(CGRectMake(0, 0, size.width, size.height)); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
The code creates a new
CoreGraphics image context with the options passed as parameters; size, opaqueness, and scale. By passing
0 for scale, iOS automatically chooses the appropriate value for the current device.
Then, the context fill colour is set to
[UIColor whiteColor]. Immediately, the canvas is then actually filled with that color, by using
UIRectFill() and passing a rectangle which fills the canvas.
UIImage is then created of the current context, and the context is closed. Therefore, the image variable contains a
UIImage of the desired size, filled white.