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

前端 未结 3 445
北海茫月
北海茫月 2021-02-07 20:32

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:41

    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();
    
    0 讨论(0)
  • 2021-02-07 20:49

    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();
    
    0 讨论(0)
  • 2021-02-07 20:56

    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.

    0 讨论(0)
提交回复
热议问题