How to create a black UIImage?

后端 未结 5 1093
无人共我
无人共我 2021-02-08 21:42

I\'ve looked around everywhere, but I can\'t find a way to do this. I need to create a black UIImage of a certain width and height (The width and height change, so I can\'t just

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-08 22:15

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(w,h), NO, 0);
    UIBezierPath* p =
        [UIBezierPath bezierPathWithRect:CGRectMake(0,0,w,h)];
    [[UIColor blackColor] setFill];
    [p fill];
    UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    Now im is the image.

    That code comes almost unchanged from this section of my book: http://www.apeth.com/iOSBook/ch15.html#_graphics_contexts

提交回复
热议问题