我使用下面的函数来旋转一个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;
}谢谢
发布于 2016-04-06 12:58:41
尝尝这个
https://stackoverflow.com/questions/33028618
复制相似问题