0
我正在使用以下函數來旋轉NSImage。它使用塊代碼爲了正確渲染視網膜。現在的問題是,它在非視網膜屏幕上呈現模糊。在非視網膜上使用塊代碼模糊NSImage旋轉
我試着檢查視網膜顯示器[NSWindow backingScaleFactor],然後在非視網膜顯示器上使用非阻擋方法,但是這種情況無法使用 - 如果用戶有視網膜Mac,但是正在向外部非視網膜顯示器顯示時,檢查backingScaleFactor會報告視網膜屏幕。後來我發現蘋果的開發者網站這個文件:
但它坦率地說不可思議。如何修改以下功能以在非視網膜顯示上模糊?
- (NSImage *)imageRotatedByDegrees:(CGFloat)degrees {
// calculate the bounds for the rotated image
NSRect imageBounds = {NSZeroPoint, [self size]};
NSBezierPath *boundsPath = [NSBezierPath bezierPathWithRect:imageBounds];
NSAffineTransform *transform = [NSAffineTransform transform];
[transform rotateByDegrees:degrees];
[boundsPath transformUsingAffineTransform:transform];
NSRect rotatedBounds = {NSZeroPoint, [boundsPath bounds].size};
// center the image within the rotated bounds
imageBounds.origin.x = NSMidX(rotatedBounds) - (NSWidth (imageBounds)/2);
imageBounds.origin.y = NSMidY(rotatedBounds) - (NSHeight (imageBounds)/2);
NSImage *rotatedImage = [NSImage imageWithSize:rotatedBounds.size flipped:NO drawingHandler:^BOOL (NSRect dstRect) {
// set up the rotation transform
NSAffineTransform *transform=[NSAffineTransform transform];
[transform translateXBy:+(NSWidth(rotatedBounds)/2) yBy:+(NSHeight(rotatedBounds)/2)];
[transform rotateByDegrees:degrees];
[transform translateXBy:-(NSWidth(rotatedBounds)/2) yBy:-(NSHeight(rotatedBounds)/2)];
// draw the original image, rotated, into the new image
[transform concat];
[self drawInRect:imageBounds fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
return YES;
}];
return rotatedImage;
}
由於