2013-06-12 29 views
0

目前我正在爲iPhone和iPad的朋友製作流媒體廣播應用程序。Xcode中的視網膜圖像爆炸4次

在將我的設計實現到代碼中時,我觸發了一個有趣的錯誤(?)。我希望在背景上顯示專輯封面,並使用此示例tutorial來掩蓋。

它可以在低分辨率iPhone上正常工作,但只要我在iPhone 4上測試它(測試設備和仿真器),圖片就會顯示爲應該是4x的大小。

enter image description here

應該像這樣顯示:enter image description here

我已經添加了正常的照片,還有@ 2倍的,其在320×320 & 640x640(@ 2X)進來 的最後一件事我應該添加,如果我不掩蓋圖像,它工作正常。但我相信面具的作品(如果它不會被炸燬4倍)。所以很可能,代碼會放大圖片兩次,而不是一次。

增加一點我的代碼:

albumArt = [[UIImageView alloc] init]; 
[albumArt setFrame:CGRectMake(0, 0, 320, 320)]; 
UIImage *image = [UIImage imageNamed:@"testPopArt.png"]; 
UIImage *mask = [UIImage imageNamed:@"popArtMask.png"]; 
finalAlmbumArt = [self maskImage:image withMask:mask]; 
[albumArt setBackgroundColor:[UIColor colorWithPatternImage:finalAlmbumArt]]; 
[appBackground addSubview:albumArt]; 
+0

你可以發佈圖像的大小(正常和視網膜)。 – rckoenes

+0

將它們添加到說明中(320x320&640x640)。面具是完全相同的大小btw! ;) –

回答

1

您NEET告訴UIImage的規模:

- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { 

    CGImageRef maskRef = maskImage.CGImage; 

    CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), 
             CGImageGetHeight(maskRef), 
             CGImageGetBitsPerComponent(maskRef), 
             CGImageGetBitsPerPixel(maskRef), 
             CGImageGetBytesPerRow(maskRef), 
             CGImageGetDataProvider(maskRef), NULL, false); 

    CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); 
    CGFloat scale = [UIScreen mainScreen].scale; 
    return [UIImage imageWithCGImage:masked scale:scale orientation:UIImageOrientationDown]; 

} 

你也許還帶着CAGradientLayer得到的效果這樣你就不必製作新的圖像。這將會減少CPU密集度。

+0

我明白了,完全看了看!謝謝,感激。奇蹟般有效 –