以编程方式获取UIview + glview [英] take screen Programmatically of UIview+glview

查看:148
本文介绍了以编程方式获取UIview + glview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的uiview中有glview,现在我必须拍摄uiview和glview的组合视图。
i googled很多,但我发现任何有用的东西,我知道如何采取glview scrrenshot

i have glview in my uiview ,now i have to take scrren shot of combine view of uiview and glview. i googled lot but i dnt found any thing useful i know how to take scrrenshot of glview


nt width = glView.frame。 size.width;
int height = glView.frame.size.height;

nt width = glView.frame.size.width; int height = glView.frame.size.height;



NSInteger myDataLength = width * height * 4;
// allocate array and read pixels into it.
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, width, height, 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 < height; y++)
{
    for(int x = 0; x < width * 4; x++)
    {
        buffer2[((height - 1) - y) * width * 4 + x] = buffer[y * 4 * width + 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 * width;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
return myImage;


推荐答案

现在获取屏幕截图似乎相当棘手,特别是当您混合使用UIKit和OpenGL ES时:曾经有 UIGetScreenImage(),但 Apple再次私有化并拒绝使用它的应用程序。

It seems like it's pretty tricky to get a screenshot nowadays, especially when you're mixing the UIKit and OpenGL ES: there used to be UIGetScreenImage() but Apple made it private again and is rejecting apps that use it.

相反,有两个解决方案到替换它: UIKit应用程序中的屏幕截图 OpenGL ES查看快照。前者不捕获OpenGL ES或视频内容,而后者为OpenGL ES。

Instead, there are two "solutions" to replace it: Screen capture in UIKit applications and OpenGL ES View Snapshot. The former does not capture OpenGL ES or video content while the later is only for OpenGL ES.

另一个技术说明如何截取包含UIKit的应用程序的屏幕截图和相机元素?,在这里他们基本上说:你需要首先捕捉相机图片,然后在渲染视图层次结构时,在上下文中绘制该图像。

There is another technical note How do I take a screenshot of my app that contains both UIKit and Camera elements?, and here they essentially say: You need to first capture the camera picture and then when rendering the view hierarchy, draw that image in the context.

同样适用于OpenGL ES:您首先需要为OpenGL ES视图渲染快照,然后将UIKit视图层次结构渲染到图像上下文中并绘制OpenGL图像ES视图在它上面。非常难看,根据您的视图层次结构,它实际上可能不是您在屏幕上看到的内容(例如,如果您的OpenGL视图前面有视图)。

The very same would apply for OpenGL ES: You would first need to render a snapshot for your OpenGL ES view, then render the UIKit view hierarchy into an image context and draw the image of your OpenGL ES view on top of it. Very ugly, and depending on your view hierarchy it might actually not be what you're seeing on screen (e. g. if there are views in front of your OpenGL view).

这篇关于以编程方式获取UIview + glview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆