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

前端 未结 3 1227
无人及你
无人及你 2021-02-07 20:11

In mac osx (cocoa), It is very easy to make a blank image of a specific size and draw to it off screen:

NSImage* image = [[NSImage alloc] initWithSize:NSMakeSi         


        
3条回答
  •  北海茫月
    2021-02-07 20:42

    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();
    

提交回复
热议问题