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];

 

posted @ 2017-03-01 20:20  mlj318  阅读(746)  评论(0编辑  收藏  举报