#if objc
- (NSData*)BitmapToArray:(UIImage*) bmp {
CGDataProviderRef provider = CGImageGetDataProvider(bmp.CGImage);
NSData* data = (id)CFBridgingRelease(CGDataProviderCopyData(provider));
return data;
}
- (UIImage*)ArrayToBitmap:(NSData*)data :(int)width :(int)height {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(
data.bytes,
width,
height,
8,
4*width,
colorSpace,
kCGImageAlphaNoneSkipLast);
CFRelease(colorSpace);
CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
CGContextRelease(bitmapContext);
UIImage* img = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return img;
}