ITeye博客

[cocos2d-iphone]ios6截图问题

119568242 · 2013-04-25 20:56 · cocos2d-iphone · 移动开发 · Markdown

相信使用cocos2d官方论坛提供的截屏方法,或者其他使用openGL方式截屏的同志们,会发现在ios6的真机下,这种截屏方式无效。 下面给出两种解决方案,已经在iphone4s 和 iphone5 真机测试过,并支持iphone5的宽屏 

 方案1:修改GLView preserveBackbuffer参数 为YES 将代码: 

EAGLView *glView = [EAGLView viewWithFrame:[window bounds]   pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8   depthFormat:0 // GL_DEPTH_COMPONENT16_OES ]; 

 修改成 

EAGLView *glView = [EAGLView viewWithFrame:[window bounds]                             pixelFormat:kEAGLColorFormatRGB565 depthFormat:0 preserveBackbuffer:YES  sharegroup:nil  multiSampling:NO                                numberOfSamples:0]; 

 方案2:使用CCDirector方式截屏 代码如下 

 

+(UIImage*) makeaShot

{

    [CCDirector sharedDirector].nextDeltaTimeZero = YES;

    

    CGSize winSize = [CCDirector sharedDirector].winSize;

    

    CCLayerColor* whitePage = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 0) width:winSize.width height:winSize.height];

    whitePage.position = ccp(winSize.width/2, winSize.height/2);

    

    CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];

    [rtx begin];

    [whitePage visit];

    [[[CCDirector sharedDirector] runningScene] visit];

    [rtx end];

    

    return [rtx getUIImageFromBuffer];

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。