2015-10-09 10 views
0

Я использую следующую функцию для вращения NSImage. Он использует блок-код для правильного отображения сетчатки. Теперь проблема заключается в том, что она создает размытость на экранах с сетчатой ​​сеткой.Вращение NSImage с использованием блочного кода размытым по не сетчатке

Я попытался проверить отображение сетчатки [NSWindow backingScaleFactor], а затем использовать неблокирующий метод на дисплеях без сетчатки, но это случай, когда он не работает - если у пользователя есть сетчатка Mac, но отображается на внешнем дисплее, не отображающем сетчатку, контрольная поддержкаScaleFactor сообщает экран сетчатки. Затем я нашел этот документ на сайте разработчика от Apple:

API-интерфейсы для поддержки высокого разрешения https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/APIs/APIs.html

Но это откровенно неисповедимы. Как можно изменить следующую функцию, чтобы не размываться на дисплеях без сетчатки?

- (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; 
} 

Благодаря

ответ

0

Попробуйте

  • (NSImage *) rotateImagedByDegrees: (CGFloat) градусов изображения: (NSImage *) sourceImage {

    NSImage *image = sourceImage; 
    
    if (degrees == 0) 
    { 
        return image; 
    } 
    else 
    { 
    
        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 rotateByDegrees:-1.0 * degrees]; 
        [boundsPath transformUsingAffineTransform:transform]; 
        NSRect rotatedBounds = {NSZeroPoint, [boundsPath bounds].size}; 
        imageBounds.origin.x = NSMidX(rotatedBounds) - (NSWidth(imageBounds)/2); 
        imageBounds.origin.y = NSMidY(rotatedBounds) - (NSHeight(imageBounds)/2); 
    
        rotatedImage = [NSImage imageWithSize:rotatedBounds.size flipped:NO drawingHandler:NO]; 
    
        NSAffineTransform* transform1 = [NSAffineTransform transform]; 
        [transform1 translateXBy:+(NSWidth(rotatedBounds)/2) yBy:+(NSHeight(rotatedBounds)/2)]; 
        [transform1 rotateByDegrees:-1.0 * degrees]; 
        [transform1 translateXBy:-(NSWidth(rotatedBounds)/2) yBy:-(NSHeight(rotatedBounds)/2)]; 
        [rotatedImage lockFocus] ; 
        [transform1 concat] ; 
    
        [sourceImage drawInRect:imageBounds 
            fromRect:NSMakeRect(0.0, 0.0, [sourceImage size].width, [sourceImage size].height) 
            operation:NSCompositeSourceOver fraction:1.0]; 
    
        [rotatedImage unlockFocus] ; 
        return rotatedImage; 
    

    } }

 Смежные вопросы

  • Нет связанных вопросов^_^