33 #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 #import "ImageConversion.h" 37 @implementation ImageConversion
44 CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
46 if (CGColorSpaceGetModel(colorSpace) == kCGColorSpaceModelMonochrome) {
47 NSLog(
@"Input UIImage is grayscale");
50 CGContextRef contextRef = CGBitmapContextCreate(gray.bitmap,
57 kCGBitmapByteOrderDefault);
59 CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
60 CGContextRelease(contextRef);
68 NSLog(
@"Input UIImage is color");
71 colorSpace = CGColorSpaceCreateDeviceRGB();
73 CGContextRef contextRef = CGBitmapContextCreate(color.bitmap,
79 kCGImageAlphaNoneSkipLast |
80 kCGBitmapByteOrderDefault);
82 CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
83 CGContextRelease(contextRef);
92 + (
vpImage<
unsigned char>)vpImageGrayFromUIImage:(UIImage *)image
94 CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
96 if (CGColorSpaceGetModel(colorSpace) == kCGColorSpaceModelMonochrome) {
97 NSLog(
@"Input UIImage is grayscale");
100 CGContextRef contextRef = CGBitmapContextCreate(gray.bitmap,
107 kCGBitmapByteOrderDefault);
109 CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
110 CGContextRelease(contextRef);
114 NSLog(
@"Input UIImage is color");
117 colorSpace = CGColorSpaceCreateDeviceRGB();
119 CGContextRef contextRef = CGBitmapContextCreate(color.bitmap,
123 4 * image.size.width,
125 kCGImageAlphaNoneSkipLast |
126 kCGBitmapByteOrderDefault);
128 CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
129 CGContextRelease(contextRef);
141 + (UIImage *)UIImageFromVpImageColor:(const
vpImage<
vpRGBa> &)I
143 NSData *data = [NSData dataWithBytes:I.bitmap length:I.getSize()*4];
144 CGColorSpaceRef colorSpace;
146 colorSpace = CGColorSpaceCreateDeviceRGB();
148 CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
151 CGImageRef imageRef = CGImageCreate(I.getWidth(),
157 kCGImageAlphaNone|kCGBitmapByteOrderDefault,
161 kCGRenderingIntentDefault
166 UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
167 CGImageRelease(imageRef);
168 CGDataProviderRelease(provider);
169 CGColorSpaceRelease(colorSpace);
177 + (UIImage *)UIImageFromVpImageGray:(const
vpImage<
unsigned char> &)I
179 NSData *data = [NSData dataWithBytes:I.bitmap length:I.getSize()];
180 CGColorSpaceRef colorSpace;
182 colorSpace = CGColorSpaceCreateDeviceGray();
184 CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
187 CGImageRef imageRef = CGImageCreate(I.getWidth(),
193 kCGImageAlphaNone|kCGBitmapByteOrderDefault,
197 kCGRenderingIntentDefault
202 UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
203 CGImageRelease(imageRef);
204 CGDataProviderRelease(provider);
205 CGColorSpaceRelease(colorSpace);
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Definition of the vpImage class member functions.