我想知道在Objective-C(Mac osx)中是否可以通过编程创建空白图像?我的需求是创建一个水印,有一个源图像..但我需要创建另一个图像,并向该图像添加一些文本,然后将第二个图像与第一个图像绑定,以便它显示为水印。这样的图像能否创建?我知道如何合并两个图像,但不知道如何通过编程创建图像并在其上添加一些文本。
我想知道在Objective-C(Mac osx)中是否可以通过编程创建空白图像?我的需求是创建一个水印,有一个源图像..但我需要创建另一个图像,并向该图像添加一些文本,然后将第二个图像与第一个图像绑定,以便它显示为水印。这样的图像能否创建?我知道如何合并两个图像,但不知道如何通过编程创建图像并在其上添加一些文本。
您可以使用以下方法创建一个空的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();
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