2016-04-06 23 views
0

Bir UIImage'ı döndürüyorum Bir ölçek değerine göre. Ölçekim ve Rotasyon iyi çalışıyor ancak sorun uiimage döndükten sonra, görüntü boyutu (genişlik & Yükseklik) azalıyor . Sorunu çözmek için herhangi bir fikrin var mı? Image before RotationUIImage boyutu (width & Height) döndürüldükten sonra azalıyor

Image After Rotation

kod i kullanıyorum
:

UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.image.size.width, self.image.size.height)]; 
    CGAffineTransform t = CGAffineTransformMakeRotation(self.lastContentOffset/5); 
    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, 5.0); 

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

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    self.rotatedImage = newImage; 

cevap

0

imajınızı varsayalım boyutunda HxH oldu. 45 derece (M_PI/2 radyan) rotasyonundan sonra, boyutu sqrt(2)*H x sqrt(2)*H olacaktır. Döndürülmüş görüntüyü sığdırmak için daha büyük bağlamlara ihtiyacınız var. Aksi takdirde bir görüntünün köşeleri kesilir. Ayrıca daha büyük görüntüyü sığdırmak için daha büyük UIImageView gerekir. Aksi takdirde, UIImageView boyutuna otomatik ölçeklendirilecek.

+0

Teşekkürler arkadaşım, bağlam boyutunu değiştirdim, işe yaradı @ s0urcer –

İlgili konular