首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

iphone app开发心得(三)

2012-09-02 
iphone app开发经验(三)1.xcode之宏2.怎样从ipa中提取PNG文件3.CALayer简单教程4.两个有用的颜色[UIColor

iphone app开发经验(三)
1.xcode之宏



2.怎样从ipa中提取PNG文件



3.CALayer简单教程



4.两个有用的颜色

[UIColor colorWithRed:0.75 green:0.75 blue:0.75 alpha:1.0], // Silver
[UIColor colorWithRed:1.00 green:0.84 blue:0.00 alpha:1.0], // Gold

5.在 cocos2d 中将屏幕内容截取为图片

+ (UIImage*) screenshotUIImage{    CGSize displaySize  = [[CCDirector sharedDirector] displaySizeInPixels];    CGSize winSize      = [[CCDirector sharedDirector] winSizeInPixels];    //Create buffer for pixels    GLuint bufferLength = displaySize.width * displaySize.height * 4;    GLubyte* buffer = (GLubyte*)malloc(bufferLength);    //Read Pixels from OpenGL    glReadPixels(0, 0, displaySize.width, displaySize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);    //Make data provider with data.    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, bufferLength, NULL);    //Configure image    int bitsPerComponent = 8;    int bitsPerPixel = 32;    int bytesPerRow = 4 * displaySize.width;    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;    CGImageRef iref = CGImageCreate(displaySize.width, displaySize.height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);    uint32_t* pixels = (uint32_t*)malloc(bufferLength);    CGContextRef context = CGBitmapContextCreate(pixels, winSize.width, winSize.height, 8, winSize.width * 4, CGImageGetColorSpace(iref), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);    CGContextTranslateCTM(context, 0, displaySize.height);    CGContextScaleCTM(context, 1.0f, -1.0f);    switch ([CCDirector sharedDirector].deviceOrientation)    {        case CCDeviceOrientationPortrait: break;        case CCDeviceOrientationPortraitUpsideDown:            CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(180));            CGContextTranslateCTM(context, -displaySize.width, -displaySize.height);            break;        case CCDeviceOrientationLandscapeLeft:            CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(-90));            CGContextTranslateCTM(context, -displaySize.height, 0);            break;        case CCDeviceOrientationLandscapeRight:            CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(90));            CGContextTranslateCTM(context, displaySize.height-displaySize.width, -displaySize.height);            break;    }    CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, displaySize.width, displaySize.height), iref);    CGImageRef imageRef = CGBitmapContextCreateImage(context);    UIImage *outputImage = [[[UIImage alloc] initWithCGImage:imageRef] autorelease];    //Dealloc    CGImageRelease(imageRef);    CGDataProviderRelease(provider);    CGImageRelease(iref);    CGColorSpaceRelease(colorSpaceRef);    CGContextRelease(context);    free(buffer);    free(pixels);    return outputImage;}


6.禁止锁屏
[UIApplication sharedApplication].idleTimerDisabled=YES;

热点排行