[cocos2d-iphone]ios6截图问题

相信使用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(2552552550width: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 sharedDirectorrunningScenevisit];

    [rtx end];

    

    return [rtx getUIImageFromBuffer];

}

猜你喜欢

转载自poolo.iteye.com/blog/1853792