首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >非视网膜上块码模糊的NSImage旋转

非视网膜上块码模糊的NSImage旋转
EN

Stack Overflow用户
提问于 2015-10-09 01:44:28
回答 1查看 209关注 0票数 0

我使用下面的函数来旋转一个NSImage。它使用块代码,以便正确地在视网膜上渲染。现在的问题是,它会使非视网膜屏幕变得模糊。

我试着检查视网膜显示器NSWindow backingScaleFactor,然后在非视网膜显示器上使用一种非阻塞的方法,但在这种情况下,它不起作用--如果用户有一个视网膜Mac,但正在向外部非视网膜显示器显示,检查backingScaleFactor报告一个视网膜屏幕。然后我在苹果的开发者网站上找到了这个文档:

支持高分辨率 https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/APIs/APIs.html的API

但坦率地说,这是无法理解的。如何在非视网膜显示器上改变以下功能以避免模糊?

代码语言:javascript
复制
- (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;
}

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-04-06 12:58:41

尝尝这个

  • (NSImage*)rotateImagedByDegrees:(CGFloat)degrees图像:(NSImage *)sourceImage { NSImage* == = sourceImage;if (== 0) {返回图像;} NSRect imageBounds = {NSZeroPoint,sourceImage size};NSSize rotatedSize = NSMakeSize(sourceImage.size.height,sourceImage.size.width);NSImage * rotatedImage = [NSImage alloc initWithSize:rotatedSize];NSBezierPath* boundsPath = NSBezierPath bezierPathWithRect:imageBounds;NSAffineTransform* transform = NSAffineTransform transform *transform=NSAffineTransform transform:-1.0度;boundsPath变换NSAffineTransform: transform;NSImage={en20#,en22#};_x= NSMidX(rotatedBounds) - (NSWidth(imageBounds) / 2);_(_transform1 translateXBy:-(NSWidth(rotatedBounds) / 2) yBy:-(NSHeight(rotatedBounds) / 2);rotatedImage lockFocus;transform1 concat;[sourceImage drawInRect:ImageE犬来自return :NSMakeRect( 0.0,0.0,sourceImage size.width,sourceImage size.height)操作:NSCompositeSourceOver分数:1.0];rotatedImage unlockFocus;返回rotatedImage; }}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33028618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档