将RGB数据保存为png图片

- (void)rgbSavePngImage:(NSInteger)wid height:(NSInteger)hei

{

CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;

CFDataRef data2 = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, rgb_frame, wid*hei*3,kCFAllocatorNull);

CGDataProviderRef provider = CGDataProviderCreateWithCFData(data2);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGImageRef cgImage = CGImageCreate(wid,

hei,

8,

24,

wid*3,

colorSpace,

bitmapInfo,

provider,

NULL,

NO,

kCGRenderingIntentDefault);

CGColorSpaceRelease(colorSpace);

UIImage *image = [UIImage imageWithCGImage:cgImage];

CGImageRelease(cgImage);

CGDataProviderRelease(provider);

CFRelease(data2);

NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/Test.png"];

[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];

}

你可能感兴趣的:(将RGB数据保存为png图片)