Programmatically create image from UILabel

前端 未结 3 1576
谎友^
谎友^ 2021-01-02 20:48

I want to use a UILabel to create an RGBA stream of bytes image representation programmatically (at runtime).

For example, I want to create a UILabel in a specific

3条回答
  •  梦毁少年i
    2021-01-02 21:52

    This should work:

    UIGraphicsBeginImageContext(yourLabel.bounds.size);
    [yourLabel.layer renderInContext:UIGraphicsGetCurrentContext()];
    CGImageRef viewImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
    UIGraphicsEndImageContext();
    

    UIGraphicsGetImageFromCurrentImageContext() returns an instance of UIImage.

提交回复
热议问题