mtm*_*ock 11 cocoa-touch objective-c nsimage uiimage
在mac osx(cocoa)中,很容易制作一个特定大小的空白图像并在屏幕上绘制它:
NSImage* image = [[NSImage alloc] initWithSize:NSMakeSize(64,64)];
[image lockFocus];
/* drawing code here */
[image unlockFocus];
Run Code Online (Sandbox Code Playgroud)
但是,在iOS(可可触摸)中似乎没有对UIImage的等效调用.我想使用UIImage(或其他一些等效类)来做同样的事情.也就是说,我想制作一个明确的大小,最初是空的图像,我可以使用UIRectFill(...)和之类的调用来绘制[UIBezierPath stroke].
我该怎么做?
这里需要CoreGraphics,因为UIImage没有像您解释的那样具有高级功能.
UIGraphicsBeginImageContext(CGSizeMake(64,64));
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing code here (using context)
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6876 次 |
| 最近记录: |