iosuikitcore-graphicsgraphicscontext

On iOS, Is there a way to get the size of an ImageContext after creating it using UIGraphicsBeginImageContextWithOptions?


If an image context is created using:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(768, 768), YES, 1.0);

is there a way to get the size of the context later on? The size for sure is there when the image is obtained from the context, but while drawing, is there also a way to get the width and size of it?


Solution

  • For a bitmap context as above you can use:

    CGContextRef context = UIGraphicsGetCurrentContext();
    size_t width = CGBitmapContextGetWidth(context);
    size_t height = CGBitmapContextGetHeight(context);