---
title: "[cocos2d-iphone]ios6截图问题"
author: "119568242"
date: "2013-04-25T20:56:18Z"
tags: []
categories: ["移动开发"]
slug: "cocos2d-iphone-ios6"
draft: false
lastmod: "2013-04-25T20:56:18Z"
id: 1853792
url: "https://poolo.iteye.com/blog/1853792"
---

相信使用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];

}