2015-03-02 76 views
1

我有一個問題,旋轉UIImage沒有質量損失。現在我正在使用BFKit提供的ready方法imageRotatedByDegrees:,但是我的圖像變得分散(模糊)。旋轉UIImage沒有質量損失

示例代碼::

- (UIImage *)imageRotatedByDegrees:(CGFloat)degrees 
{ 
    // calculate the size of the rotated view's containing box for our drawing space 
    UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.size.width, self.size.height)]; 
    CGAffineTransform t = CGAffineTransformMakeRotation(DegreesToRadians(degrees)); 
    rotatedViewBox.transform = t; 
    CGSize rotatedSize = rotatedViewBox.frame.size; 

    // Create the bitmap context 
    UIGraphicsBeginImageContext(rotatedSize); 
    CGContextRef bitmap = UIGraphicsGetCurrentContext(); 

    // Move the origin to the middle of the image so we will rotate and scale around the center. 
    CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2); 

    // // Rotate the image context 
    CGContextRotateCTM(bitmap, DegreesToRadians(degrees)); 

    // Now, draw the rotated/scaled image into the context 
    CGContextScaleCTM(bitmap, 1.0, -1.0); 
    CGContextDrawImage(bitmap, CGRectMake(-self.size.width/2, -self.size.height/2, self.size.width, self.size.height), [self CGImage]); 

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return newImage; 
} 

有另一種方式沒有質量損失旋轉的UIImage

UIImage *image = [[UIImage imageNamed:@"car"] imageRotatedByDegrees:(((float)arc4random()/ARC4RANDOM_MAX) * (360))]; 

imageRotatedByDegrees碼?

回答

3

我BFKit的作者,當我讀到了你的問題,我研究了有關問題。 在最新版本中(1.6.4)我修復了這個問題!

現在圖像將不再被擴散(模糊)。

0

我的目標是旋轉我的MKAnnotationView中的圖像。所以我通過旋轉不是圖像解決了這個問題,而是整個MKAnnotationView。

幫助我的答案是this

我的代碼在MKMapViewDelegate方法的MapView:viewForAnnotation:

annotationView.transform = CGAffineTransformMakeRotation((((float)arc4random()/ARC4RANDOM_MAX) * (360)));