我的应用程序仅在纵向视图中。
我正在从相机拍摄图像并将其显示到图像视图中UIImagePickerController
。现在,如果我旋转设备,它会在横向视图中拍摄照片,并且图像尺寸从1936*2592
(即纵向)变为2592*1936
.
现在我想在我的纵向视图中显示相同的图像,就像默认相机一样。
请告诉我我该怎么做?
还是可以UIImagePicker
只锁定纵向?
您可以调整图像大小
- (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 ;
}