gpt4 book ai didi

objective-c - UIImage 与 NSImage : Drawing to an off screen image in iOS

转载 作者:太空狗 更新时间:2023-10-30 03:26:18 25 4
gpt4 key购买 nike

在 mac osx (cocoa) 中,制作特定尺寸的空白图像并在屏幕外绘制它非常容易:

NSImage* image = [[NSImage alloc] initWithSize:NSMakeSize(64,64)];
[image lockFocus];
/* drawing code here */
[image unlockFocus];

但是,在 iOS (cocoa touch) 中似乎没有对 UIImage 的等效调用。我想使用 UIImage(或其他一些等效类)来做同样的事情。也就是说,我想制作一个明确大小的、最初为空的图像,我可以使用像 UIRectFill(...) 这样的调用来绘制它。和 [UIBezierPath stroke] .

我该怎么做?

最佳答案

这里需要 CoreGraphics,因为 UIImage 没有像您解释的那样的高级功能..

UIGraphicsBeginImageContext(CGSizeMake(64,64));

CGContextRef context = UIGraphicsGetCurrentContext();
// drawing code here (using context)

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

关于objective-c - UIImage 与 NSImage : Drawing to an off screen image in iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9829475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com