- (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
类型吗?