int width = 100;
int height = 100;
int bytes_per_pix = 4;
Byte *rgbbuffer = malloc(width*height*bytes_per_pix);
for(int i=0;i<width*height*bytes_per_pix;i+=bytes_per_pix)
{
rgbbuffer[i+3] = 200;//这个是alfa值,因为是小字节序所以ARGB的内存储存方式为BGRA
rgbbuffer[i+1] = 100;
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef newContext = CGBitmapContextCreate(rgbbuffer,
width, height, 8,
width * bytes_per_pix,
colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGImageRef frame = CGBitmapContextCreateImage(newContext);
self.imageview.image = [UIImage imageWithCGImage:frame];
CGImageRelease(frame);
CGContextRelease(newContext);
CGColorSpaceRelease(colorSpace);
free(rgbbuffer);