ios 从rgb array生成UIImage并显示,oc版

    const size_t Width = 1080;
    const size_t Height = 1080;
    const size_t Area = Width * Height;
    const size_t channles = 4; // rgba
    std::vector<uint8_t> output(Area*channles);
    uint8_t *outputdata = output.data();
 
     
    // create the bitmap context:
    const size_t BitsPerComponent = 8;
    const size_t BytesPerRow=((BitsPerComponent * Width) / 8) * channles;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef gtx = CGBitmapContextCreate(outputdata, Width, Height, BitsPerComponent, BytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
    
    // create the image:
    CGImageRef toCGImage = CGBitmapContextCreateImage(gtx);
    UIImage *image = [[UIImage alloc] initWithCGImage:toCGImage];
    
    [self.imageView setImage:image];
原文地址:https://www.cnblogs.com/mlj318/p/6486053.html