2

我想同时拍摄设备相机和CClayer的截图。

但是当我编写以下代码时,结果是:

我只能截取CClayer的截图,不能同时截取两者。

宏 'UIGetScreenImage' 可以解决这个问题,但我听说 Apple 拒绝了该代码,因为它是非法的。

有关如何解决此问题的任何想法/链接/详细信息?

我已经查看了该链接,但它并不能帮助我解决问题。

PS 我使用 Cocos2D 2.1 但我是初学者。

//in AppDelegate.h

@property (nonatomic, retain) UIView *overlay;

//in AppDelegate.m

[CCDirector sharedDirector].view.backgroundColor = [UIColor clearColor];
[CCDirector sharedDirector].view.opaque = NO;
//director_.view.opaque=NO;
//director_.view.backgroundColor= [UIColor clearColor];
glClearColor(0.0, 0.0, 0.0, 0.0);

// prepare the overlay view and add it to the window
self.overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.overlay.opaque = NO;
self.overlay.backgroundColor = [UIColor clearColor];
[window_ addSubview:self.overlay];
[window_ bringSubviewToFront:overlay];
self.overlay.hidden = YES;

//in CameraScene.m
-(id) init
{
#define CAMERA_TRANSFORM  1.24299
if( (self = [super init])) {
    UIView* overlay = self.appdelegate.overlay;
    overlay.hidden = NO;

    @try {
        uip = [[[UIImagePickerController alloc] init] autorelease];
        uip.sourceType = UIImagePickerControllerSourceTypeCamera;
        uip.showsCameraControls = NO;
        uip.toolbarHidden = YES;
        uip.navigationBarHidden = YES;
        uip.wantsFullScreenLayout = YES;
        uip.cameraViewTransform = CGAffineTransformScale(uip.cameraViewTransform, CAMERA_TRANSFORM, CAMERA_TRANSFORM);
    }
    @catch (NSException * e) {
        [uip release];
        uip = nil;
    }
    @finally {
        if(uip) {
            [overlay addSubview:[uip view]];
            [overlay release];
        }
    }

    // ask director the the window size
    self.touchEnabled=YES;

    _state=kIdle;
    [self createGUI];
    [self createAndAnimateModel];
}
return self;
}
//for screeshot
- (UIImage*)makeaShot {
/*CGImageRef screen = UIGetScreenImage();
UIImage* screenImage = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
return  screenImage;*/

/*UIGraphicsBeginImageContext(self.winSize);
[[CCDirector sharedDirector].view renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;*/

/*[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize winSize = [CCDirector sharedDirector].winSize;

CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];
[rtx beginWithClear:0 g:0 b:0 a:1.0f];
[[[CCDirector sharedDirector] runningScene] visit];
[rtx end];

return [rtx getUIImage];*/

//return [AWScreenshot takeAsImage];

/*CGRect rect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[[CCDirector sharedDirector].view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;0*/
/*CGImageRef screen = [AWScreenshot takeAsCGImage];
 UIImage* screenImage = [UIImage imageWithCGImage:screen];
 CGImageRelease(screen);
 return  screenImage;*/

[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 getUIImage];
}
4

0 回答 0