简体   繁体   中英

iOS: How to retrieve image dimensions X, Y from CGContextRef

As it says on the can; 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 throw this context to a drawing function that will eg draw a circle touching the edges:

Do I really need to throw in the width and height as well? I am 99% sure I have seen some way to extract the width and height from the context, but I can't find it anywhere.

CGBitmapContextGetWidth // and Height

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

Thanks @ wiliz on #iphonedev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM