2013년 7월 21일 일요일

영상 출력하기


- (void)drawRect:(NSRect)dirtyRect
{
    // Get Current Context
    NSGraphicsContext * nsGraphichContext = [NSGraphicsContext currentContext];
    CGContextRef context = (CGContextRef) [nsGraphichContext graphicsPort];

    // Provider
    CGDataProviderRef provider = CGDataProviderCreateWithData(
                            NULL,
                            pDib->m_pData,      // data
                            pDib->m_nWidth * pDib->m_nHeight,   // data size
                            NULL);              // release callback
    
    // color space
    unsigned char * colorTable = new unsigned char[256];
    for(int i=0;i<256;i++)
        colorTable[i] = 255 - i;

    // 시스템에서 제공하는 기본 그레이스케일
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceGray();

    // 커스텀 그레이스케일 입력하기

    CGColorSpaceRef colorSpaceRef2 = CGColorSpaceCreateIndexed(
                    colorSpaceRef, 255, colorTable);
    delete[] colorTable;
    
    // bitmap info
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    
    // intent
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
    
    // Create CGImage
    CGImageRef imageRef = CGImageCreate(
                            pDib->m_nWidth,     // width
                            pDib->m_nHeight,    // height
                            8,                  // bitsPerComponent
                            8,                  // bitsPerPixel
                            pDib->m_nWidth,     // bytesPerRow
                            colorSpaceRef2,      // colorspace
                            bitmapInfo,         // bitmapInfo
                            provider,           // provider
                            NULL,               // decode
                            NO,                 // shoudInterpolate
                            renderingIntent);   // intent

    // Render
    NSRect myRect = NSMakeRect(dst.left, dst.top, dst.Width(), dst.Height());
    CGContextDrawImage(context, myRect, imageRef);
    
    CGImageRelease(imageRef);
}
    

댓글 없음:

댓글 쓰기