IOS: how to get X, Y image sizes from CGContextRef

As the bank says; Here is an example of why I need it:

Let's say I create a bitmap context:

size_t pixelCount = dest_W * dest_H;

typedef struct {
    uint8_t r,g,b,a;
} RGBA;

// backing bitmap store
RGBA* pixels = calloc( pixelCount, sizeof( RGBA ) );

// create context using above store
CGContextRef X_RGBA;
{
    size_t bitsPerComponent = 8;
    size_t bytesPerRow = dest_W * sizeof( RGBA );

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    // create a context with RGBA pixels
    X_RGBA = CGBitmapContextCreate( (void *)pixels, dest_W, dest_H, 
                                   bitsPerComponent, bytesPerRow, 
                                   colorSpace, kCGImageAlphaNoneSkipLast
                                   );        
    assert(X_RGBA);

    CGColorSpaceRelease(colorSpace);
}

Now I want to convey this context to a drawing function that, for example, draws a circle touching the edges:

Do you really need to cast width and height? I am 99% sure that I saw some way to extract the width and height from the context, but I can not find it anywhere.

+3
source share
1 answer
CGBitmapContextGetWidth // and Height

NB width and height probably don't make sense for non-bitmap CGContextRef

Thanks @wiliz on #iphonedev

+6
source

All Articles