objective-cimagemacosnsimagensimageview

Create Image programmatically in Objective-C


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.


Solution

  • 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