gpt4 book ai didi

iphone - 使用 openGL 捕获屏幕截图

转载 作者:行者123 更新时间:2023-12-03 19:24:09 27 4
gpt4 key购买 nike

Possible Duplicate:
I want capture screen when any game is running with opengl

我正在使用 OpenGL 开发一款 Action 游戏。
当用户播放最佳镜头时,我想捕捉它们并上传到社交网络。
我使用了很多代码,但没有成功。部分代码如下:

OpenGL ES View Snapshot

       NSInteger myDataLength = 480 * 320 * 4;

// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, 480, 320, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

// gl renders "upside down" so swap top to bottom into new array.
// there's gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y < 320; y++)
{
for(int x = 0; x < 480 * 4; x++)
{
buffer2[(319 - y) * 480 * 4 + x] = buffer[y * 4 * 480 + x];
}
}


// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);

// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 480;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

// make the cgimage
CGImageRef imageRef = CGImageCreate(480, 320, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
UIImage *image = [UIImage imageWithCGImage:imageRef];

其他代码是:

CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
[glview.parent.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但所有代码都在模拟器中生成图像而不是在设备中(仅黑白图像)

最佳答案

这个问题已经在这里得到解答。这就是我相信您正在寻找的内容

How to get UIImage from EAGLView?

关于iphone - 使用 openGL 捕获屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14373306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com