如何将BGR类型的位图转换为UIImage

时间:2016-08-23 03:53:01

标签: ios objective-c bitmap uiimage

- (UIImage *)setImage:(UIImage *)img{
    CGSize size = img.size;
    int imageW = size.width;
    int imageH = size.height;
    unsigned char *cImage = [self convertUIImageToBitmapBGR:img];

    unsigned char *poutBGRImage  = (unsigned char *)malloc(imageW * imageH * 3);
    if (!self.handle) {
    NSLog(@"init handle fail");
    }

    cv_result_t result  = cv_imagesdk_dynamic_imagetone_picture(self.handle, cImage, CV_PIX_FMT_BGR888, imageW, imageH, imageW * 3, poutBGRAImage, CV_PIX_FMT_BGR888, imageW, imageH, imageW * 3, 1.0, 1.0,1.0);

    free(cImage);

    if (result == CV_OK) {
        UIImage * image = [UIImage imageWithData:[NSData dataWithBytes:poutBGRAImage length:imageW*imageH*3]];
        free(poutBGRAImage);
        return image;
    }else{
        free(poutBGRAImage);
        return [[UIImage alloc] init];
    }
}

我可以使用UIImage函数将convertUIImageToBitmapBGR:成功转换为BGR位图。运行cv_imagesdk_dynamic_imagetone_picture:函数后,我可以将poutBGRImage作为unsigned char type变量。我现在使用[UIImage imageWithData:]但它不起作用。还有其他功能可以将unsigned char type数据转换为UIImage类型吗?

0 个答案:

没有答案