Roating CGImageRef on iOS.

For reminder to myself, rotate image on center.

    CGImageRef imageref = [self imageFromSampleBuffer:sampleBuffer];
    // or any other CGImageRef source.
    
    int w = CGImageGetWidth(imageref);
    int h = CGImageGetHeight(imageref);
    CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageref);
    CGContextRef bitmap = CGBitmapContextCreate(NULL, w, h,
                                                CGImageGetBitsPerComponent(imageref), 
                                                CGImageGetBytesPerRow(imageref),
                                                colorSpaceInfo, CGImageGetBitmapInfo(imageref));
    CGContextTranslateCTM(bitmap, w/2, h/2);
    CGContextRotateCTM(bitmap, M_PI_4);
    CGContextTranslateCTM(bitmap,  -w/2, -h/2;
    CGContextDrawImage(bitmap, CGRectMake(0, 0, w, h), imageref);
    CGImageRelease(imageref);
    imageref = CGBitmapContextCreateImage(bitmap);
    CGContextRelease(bitmap);
    return imagereff;

Comments

Popular posts from this blog

Subclassing and Signal connect on a same widget crashes PySide application on exit.

Calling OpenCV functions via Cython from Python 3.X.

Showing CPU/Memory usage on tmux status bar(tmuxのステータスバーにCPUとMemoryの使用状況を表示する)