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.
Asked
Active
Viewed 3,529 times
2 Answers
5
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();

Nikos M.
- 13,685
- 4
- 47
- 61
-
Thanks Nikos, the above code works only in iOS application. I am asking about Mac OSX. Thanks for your great time – Jio Dec 18 '13 at 09:10
3
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

Shankar BS
- 8,394
- 6
- 41
- 53
-
Thanks Shan.. Works perfectly.. I created a blank black image and displayed in the nsimageview. Now i am trying to add a text on it. Thanks... you save my time.. – Jio Dec 18 '13 at 09:26