Question

I want to know is it is possible to create a blank image programmatically in Objective-C (Mac osx)? My requirement is I want to create a watermark, so one source image is there.. But i need to create an another image and add some text to that image and bind the second image with the first one so that it will display as a watermark. Is it is possible to create an image like that? i know how to merge two images. I don't know how to create an image programmatically and add some text on it.

Was it helpful?

Solution 2

u can create image like this, hope this helps u ..


 NSImage *blackImage = [[NSImage alloc]initWithSize:NSMakeSize(22, 12)];
[blackImage lockFocus];
 NSColor *blackColor=[[NSColor blackColor]autorelease];
[blackColor set];
 NSRectFill(NSMakeRect(0, 0, 22, 12));
[blackImage unlockFocus];
[item setImage:[blackImage autorelease]];//now  you can get the black image hear item is imageView this is without ARC code u can remove autorelease if u want 


OTHER TIPS

You can create a blank png using:

// The NO here is the opaque parameter. You can set it to YES according to your needs.
UIGraphicsBeginImageContextWithOptions(CGSizeMake(150, 150), NO, 0.0);
UIImage *blankImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top