我想知道是否可以在Objective-C(Mac osx)中以编程方式创建空白图像?我的要求是我想创建一个水印,所以有一个源图像..但我需要创建另一个图像并添加一些文本到该图像并将第二个图像与第一个图像绑定,以便它将显示为水印。是否可以创建这样的图像?我知道如何合并两个图像。我不知道如何以编程方式创建图像并在其上添加一些文本。
答案 0 :(得分:4)
您可以使用以下方式创建空白png:
// 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();
答案 1 :(得分:2)
你可以像这样创建图像,希望这有助于你...
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