2012-01-07 6 views
0

this great subclass of NSWindowが見つかりましたが、ツールバーのグラデーションにノイズは追加されません。あなたがApp Store、Reeder、Twitterを詳しく見てみると、彼らはすべてグラデーション上でノイズを持っています。Mac App Storeノイズのあるツールバーのように

グラデーションにノイズを追加するにはどうすればよいですか?

私はこれを見つけましたthreadしかし、これをコードに入れる方法はわかりません。

答えて

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]; 
関連する問題