开发者

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

开发者 https://www.devze.com 2023-03-06 22:03 出处:网络
As it says on the can;here is an example of why I开发者_C百科 need it: Let\'s say I create a bitmap context:

As it says on the can; here is an example of why I开发者_C百科 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

0

精彩评论

暂无评论...
验证码 换一张
取 消