2012-01-07 31 views

回答

1

首先,所有的代碼已被添加到INAppStoreWindow,所以我沒有使用情況了。然而,對於想要知道如何做到這一點的人來說,如何通過INAppStoreWindow來完成。

首先創建一個具有噪聲的圖像的功能。

static CGImageRef createNoiseImageRef(NSUInteger width, NSUInteger height, CGFloat factor) 
{ 
    NSUInteger size = width*height; 
    char *rgba = (char *)malloc(size); srand(124); 
    for(NSUInteger i=0; i < size; ++i){rgba[i] = rand()%256*factor;} 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); 
    CGContextRef bitmapContext = 
    CGBitmapContextCreate(rgba, width, height, 8, width, colorSpace, kCGImageAlphaNone); 
    CFRelease(colorSpace); 
    free(rgba); 
    CGImageRef image = CGBitmapContextCreateImage(bitmapContext); 
    CFRelease(bitmapContext); 
    return image; 
} 

然後,圖像被用於在當前圖形疊加噪聲

static CGImageRef noisePattern = nil; 
    if (noisePattern == nil) noisePattern = createNoiseImageRef(128, 128, 0.015); 
    [NSGraphicsContext saveGraphicsState]; 
    [[NSGraphicsContext currentContext] setCompositingOperation:NSCompositePlusLighter]; 
    CGRect noisePatternRect = CGRectZero; 
    noisePatternRect.size = CGSizeMake(CGImageGetWidth(noisePattern), CGImageGetHeight(noisePattern));   
    CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; 
    CGContextDrawTiledImage(context, noisePatternRect, noisePattern); 
    [NSGraphicsContext restoreGraphicsState];