首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

(转)把两个Layer融合成一个UIImage的截图步骤

2012-07-03 
(转)把两个Layer融合成一个UIImage的截图方法//layer1CCLayer *layer1 [CCLayer node]CGPoint p1 lay

(转)把两个Layer融合成一个UIImage的截图方法

    //layer1        CCLayer *layer1 = [CCLayer node];        CGPoint p1 = layer1.anchorPoint;        [layer1 setAnchorPoint:ccp(0,0)];        CCRenderTexture *renderer01 = [CCRenderTexture renderTextureWithWidth: layer1.contentSize.width height: layer1.contentSize.height];        [renderer01 begin];        [layer1 visit];        [renderer01 end];        [layer1 setAnchorPoint: p1];        UIImage *image1 = [UIImage imageWithData:[renderer01 getUIImageAsDataFromBuffer:kCCImageFormatPNG]];    //layer2       CCLayer *layer2 = [CCLayer node];       CGPoint p2 = layer2.anchorPoint;       [layer2 setAnchorPoint:ccp(0,0)];       CCRenderTexture *renderer02 = [CCRenderTexture renderTextureWithWidth: layer2.contentSize.width height: layer2.contentSize.height];       [renderer02 begin];       [layer2 visit];       [renderer02 end];       [layer2 setAnchorPoint: p2];       UIImage *image2 = [UIImage imageWithData:[renderer02 getUIImageAsDataFromBuffer:kCCImageFormatPNG]];           //GC来了两个层开始融合        UIImage *image;        if (UIGraphicsBeginImageContextWithOptions != NULL) {            UIGraphicsBeginImageContextWithOptions(srcSize, YES, 0);        } else {            UIGraphicsBeginImageContext(srcSize);        }        [image1 drawInRect:CGRectMake(0, 0, srcSize.width, srcSize.height)];        [image2 drawInRect:CGRectMake(0, 0, srcSize.width, srcSize.height)];        image = UIGraphicsGetImageFromCurrentImageContext();        UIGraphicsEndImageContext();

热点排行