首页 > 移动平台 > 详细

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

时间:2017-03-01 21:07:36      阅读:224      评论:0      收藏:0      [点我收藏+]
    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];

 

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

原文:http://www.cnblogs.com/mlj318/p/6486053.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!