2013-07-06 95 views
1

我的應用程序僅處於縱向視圖。允許用戶在UIImagePickerController中以縱向視圖尺寸拍攝照片

我正在拍攝來自相機的圖像,並將其顯示爲從UIImagePickerController的圖像視圖。 現在,如果我旋轉設備,那麼它將以橫向視圖拍攝照片,圖像尺寸從1936*2592(用於肖像)變爲2592*1936

現在我想在我的肖像視圖中顯示與默認相機完全相同的圖像。

請告訴我該怎麼做?
還是有可能鎖定UIImagePicker只肖像?

回答

0

您可以調整圖像

- (UIImage *)imageByScalingToSize:(CGSize)targetSize 
{ 

    UIImage *sourceImage = yourImage; 
    UIImage *newImage = nil; 

    CGFloat targetWidth = targetSize.width; 
    CGFloat targetHeight = targetSize.height; 

    // CGFloat scaleFactor = 0.0; 
    CGFloat scaledWidth = targetWidth; 
    CGFloat scaledHeight = targetHeight; 

    CGPoint thumbnailPoint = CGPointMake(0.0,0.0); 

    // this is actually the interesting part: 

    UIGraphicsBeginImageContext(targetSize); 

    CGRect thumbnailRect = CGRectZero; 
    thumbnailRect.origin = thumbnailPoint; 
    thumbnailRect.size.width = scaledWidth; 
    thumbnailRect.size.height = scaledHeight; 

    [sourceImage drawInRect:thumbnailRect]; 

    newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    if(newImage == nil) NSLog(@"could not scale image"); 


    return newImage ; 
} 
+0

您好,感謝您的建議,但我已經嘗試過這種方法,如果寬度>高度然後將根據該修正的圖像,我會得到比高度寬度更根據寬高比,我將在UIImageView中留下空白區域 – Rahul

相關問題