I have an NSImage that I would like to pad out with white pixels. How can I do this?
How can I pad an NSImage with white pixels in Objective-C?
If what you need to do is add a white border around and image, here's some code
-(NSImage *)addBorderToImage: (NSImage *)oldImage
width: (CGFloat)w;
{
NSSize size;
NSRect iRect;
NSImage *newImage;
size = oldImage.size;
iRect.origin.x = w;
iRect.origin.y = w;
iRect.size = size;
size.width += 2 * w;
size.height += 2 * w;
newImage = [[NSImage alloc] initWithSize: size];
[newImage lockFocus];
[[NSColor whiteColor] drawSwatchInRect: NSMakeRect( 0 , 0 , size.width, size.height)];
[oldImage drawInRect: iRect];
[newImage unlockFocus];
return newImage;
}
code-block