2016年8月10日 星期三

iOS RGBA rawdata to UIImage

int dstW = 640;
int dstH = 480;
int bufferLength = dstW * dstH * 4;
unsigned char *dst = (unsigned char*) calloc(bufferLength, sizeof(unsigned char));

// do something on buffer dst

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, dst, bufferLength, NULL);
int bitsPerPixel = 32;
colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGImageRef dstImageRef = CGImageCreate(dstW, dstH, bitsPerComponent, bitsPerPixel, dstW * 4, colorSpaceRef,
                                       bitmapInfo, provider, NULL, NO, renderingIntent);
UIImage *dstImg = [UIImage imageWithCGImage: dstImageRef];

沒有留言:

張貼留言