我需要使用 OpenGL ES设置随机图片(类型噪声像素)。没有openGL(在ios中),我们就是这样做的:
//declare variable:
UIImage* myImage;
UIImageView *imageView;
CGRect rect;
//function whitch drawing random pixel-array picture and display it on screen ios-device;
-(void)setPicture
{
if(imageView!=NULL)
{
//Addition removal imageView
[imageView removeFromSuperview];
imageView = NULL; //
}
int width = 352; //sizes
int height = 288;
size_t bufferLength = width * height * 4; //
uint8_t* pixels = (uint8_t*)malloc(bufferLength); //
for (int i = 0; i < bufferLength/2; i++) {
pixels[i] = rand() % 255; //obtain random pixel array
}
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]; //reflect pixel array to picture
CGImageRelease(toCGImage);
CGColorSpaceRelease(space);
CGContextRelease(ctx);
free(pixels);
myImage = uiimage;
//
rect = self.view.bounds; //
if(imageView == NULL)
{
imageView = [[UIImageView alloc] initWithFrame:rect];
imageView.image = myImage;
[self.view addSubview:imageView];
NSLog(@"NULL");
} else
{
[imageView setNeedsDisplay];
NSLog(@"Dewnull");
}
}
调用我的功能后,屏幕上会显示相同的图片。
问题
是否可以使用 openGL ES 在ios屏幕上设置相似的图片?怎么做?它会比我的功能更快吗?
答案 0 :(得分:0)
请参阅'Procedural Textures: “Random” Noise'部分。它更快吗?生成,几乎肯定是肯定的,因为GPU可以轻松地并行化这个过程。但是从GPU读回来可能会很慢;我想在iOS上可能更少,因为内存是统一的。简介并查看。这取决于你对纹理做了什么。