Posted By

dio on 07/25/10


Tagged

IplImage


Versions (?)

UIImage from IplImage


 / Published in: Objective C
 

URL: http://niw.at/articles/2009/03/14/using-opencv-on-iphone/en

  1. // NOTE You should convert color mode as RGB before passing to this function
  2. - (UIImage *)UIImageFromIplImage:(IplImage *)image {
  3. CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  4. // Allocating the buffer for CGImage
  5. NSData *data =
  6. [NSData dataWithBytes:image->imageData length:image->imageSize];
  7. CGDataProviderRef provider =
  8. CGDataProviderCreateWithCFData((CFDataRef)data);
  9. // Creating CGImage from chunk of IplImage
  10. CGImageRef imageRef = CGImageCreate(
  11. image->width, image->height,
  12. image->depth, image->depth * image->nChannels, image->widthStep,
  13. colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault,
  14. provider, NULL, false, kCGRenderingIntentDefault
  15. );
  16. // Getting UIImage from CGImage
  17. UIImage *ret = [UIImage imageWithCGImage:imageRef];
  18. CGImageRelease(imageRef);
  19. CGDataProviderRelease(provider);
  20. CGColorSpaceRelease(colorSpace);
  21. return ret;
  22. }

Report this snippet  

You need to login to post a comment.