In un tutorial by RayWenderlichwrite in Objective-C
explains how to create a bitmap Image, but a lot has changed in Swift:
is right set :
let pixel = UnsafeMutablePointer<CUnsignedChar>.alloc(1)
let context:CGContextRef = CGBitmapContextCreate(pixel, width, height, bitsPerComponent, bytesForRow, colorSpace, bitmapInfo.rawValue)!and how make translate this code for print the value of RGB:
#define Mask8(x) ( (x) & 0xFF )
#define R(x) ( Mask8(x) )
#define G(x) ( Mask8(x >> 8 ) )
#define B(x) ( Mask8(x >> 16) )
/
NSLog(@"Brightness of image:");
UInt32 * currentPixel = pixels;
for (NSUInteger j = 0; j < height; j++) {
for (NSUInteger i = 0; i < width; i++) {
UInt32 color = *currentPixel;
printf("%3.0f ", (R(color)+G(color)+B(color))/3.0);
currentPixel++;
}
printf("\n");
}
free(pixels);
#undef R
#undef G
#undef BI thank everyone who can help me !!!!!