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

StackOverflow https://stackoverflow.com/questions/10781718

Question

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?

Was it helpful?

Solution

For a bitmap context as above you can use:

CGContextRef context = UIGraphicsGetCurrentContext();
size_t width = CGBitmapContextGetWidth(context);
size_t height = CGBitmapContextGetHeight(context);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top