Here's the code that generates me a picture of noise if you put it in, for example, viewDidLoadint width = 500;
int height = 500;
size_t bufferLength = width * height * 4;
uint8_t* pixels = (uint8_t*)malloc(bufferLength);
for (int i = 0; i < bufferLength; i++) {
pixels[i] = rand() % 255;
}
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(pixels, width, height, 8, width * 4, space, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast);
CGImageRef toCGImage = CGBitmapContextCreateImage(ctx);
UIImage * uiimage = [[UIImage alloc] initWithCGImage:toCGImage];
CGImageRelease(toCGImage);
CGColorSpaceRelease(space);
CGContextRelease(ctx);
free(pixels);
UIImageView *imageView = [[UIImageView alloc] initWithImage:uiimage];
[self.view addSubview:imageView];
To fill the mass with something specific.There's a piccell format that's defined by the parameters. kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast♪ That means RGBAi.e. each picsel consists of 4th bikes, sequentially red (Red), green (Green), blue (Blue), alpha (transparence). I mean, in order to set up a specific set of picsel, a sequence of 4th Byte, the last of which is 255 (i.e., without transparency) should be filled.
For example: for (int i = 0; i < width * height; i++)
{
pixels[i * 4] = 100; //баланс красного
pixels[i * 4 + 1] = 200; //баланс зеленого
pixels[i * 4 + 2] = 50; //баланс синего
pixels[i * 4 +3] = 255; //прозрачности
}