3
- (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];
    }
}

I can convert the UIImage into the BGR bitmap successfully by using the convertUIImageToBitmapBGR: function. And after running the cv_imagesdk_dynamic_imagetone_picture: function I can get the poutBGRImage as a unsigned char type variable. I use [UIImage imageWithData:] now but it doesn't work. Is there any other function to make the unsigned char type data into the UIImage type?

Bista
  • 7,869
  • 3
  • 27
  • 55
Ellise
  • 81
  • 4
  • 1
    duplicate question. Check here http://stackoverflow.com/questions/7225985/how-to-create-image-from-unsigned-char – codetiger Aug 23 '16 at 04:15

0 Answers0