UIImage vs NSImage: Drawing to an off screen image in iOS

[亡魂溺海] 提交于 2019-12-03 06:20:17

CoreGraphics is needed here, as UIImage does not have high level functions like what you explained..

UIGraphicsBeginImageContext(CGSizeMake(64,64));

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

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

You can do that as follows:

UIGraphicsBeginImageContext(CGSizeMake(64, 64));
//Drawing code here
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Here is Apple's Graphics and Drawing reference.

Something like this:

UIGraphicsBeginImageContextWithOptions(mySize, NO, 0.0f);       
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);

[myImage drawInRect:myImageRect];
[myText drawAtPoint:myOrigin withFont:myFont];

UIGraphicsPopContext();
UIImage *myNewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!