2015-03-02 5 views
1

У меня есть проблема повернуть UIImage без потери качества. Теперь я использую готовый метод, предоставляемый BFKit imageRotatedByDegrees:, но мое изображение становится рассеянным (размытым).Вращение UIImage без потери качества

Пример кода:

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

Кодекс imageRotatedByDegrees::

- (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 без потери качества?

ответ

3

Я автор BFKit, и когда я прочитал о вашем вопросе я исследовал об этой проблеме. В последней версии (1.6.4) Я исправил это!

Теперь изображение больше не будет рассеиваться (размыто).

0

Моя цель состояла в том, чтобы повернуть изображение, которое было в моем MKAnnotationView. Поэтому я решил проблему, вращая не изображение, а весь MKAnnotationView.

Ответ, который мне помог, это this.

Мой код в методе MKMapViewDelegate MAPview: viewForAnnotation::

annotationView.transform = CGAffineTransformMakeRotation((((float)arc4random()/ARC4RANDOM_MAX) * (360))); 
Смежные вопросы