CGBitmapContextGetData什么都没有返回?

时间:2012-05-22 00:20:41

标签: ios core-graphics

我有一些名为originalFrame的CGImageRef数据。使用它,我想做以下事情:

  • 使图像灰度
  • 旋转图像
  • 裁剪图像
  • 将生成的像素数据提供给外部库

但是,当我这样做时,无论我做什么,像素缓冲区都只是完全空

 // Convert to grayscale, translate, rotate, crop.
    CGColorSpaceRef graySpace = CGColorSpaceCreateDeviceGray();
    uint8_t *croppedData = (uint8_t *)malloc( sizeof(uint32_t)*CROPPED_WIDTH*CROPPED_HEIGHT );
    memset( croppedData, 0, sizeof(uint32_t)*CROPPED_WIDTH*CROPPED_HEIGHT );

    context = CGBitmapContextCreate( croppedData, CROPPED_WIDTH, CROPPED_HEIGHT, 8, height*sizeof(uint32_t), graySpace,  kCGImageAlphaNoneSkipFirst );
    CGContextClipToRect(context, CGRectMake( 0, 0,  CROPPED_WIDTH, CROPPED_HEIGHT ) );
    CGContextTranslateCTM( context, 0, width );
    CGContextRotateCTM( context, -M_PI/2 );
    CGContextDrawImage( context, CGRectMake( 0, 0, width, height ), originalFrame );

    CGImageRef tempDisplayImage = CGBitmapContextCreateImage( context );
    [self.displayLayer performSelectorOnMainThread:@selector(setContents:) withObject:(id)tempDisplayImage waitUntilDone:YES];

    CGImageRelease( tempDisplayImage );
    CGContextRelease( context );
    CGColorSpaceRelease( graySpace );

    CGImageRelease( originalFrame );

我知道翻译,旋转和裁剪是有效的,因为我的displayLayer中显示了正确的图像。尽管上下文正确地绘制了图像,但为什么croppedData缓冲区仍为空?

0 个答案:

没有答案