我在我的应用程序中使用UIImagePickerController来拍照,并且我使用自己的控件,这意味着UIImagePickerController showsCameraControls属性被设置为NO,并且我在拍摄照片的overlayView中有一个UIButton。现在,我注意到我保存在照片库中的图像实际上显示了比预览视图中显示的更大的区域。其他人也有同样的问题吗?有什么解决方案可以让图片显示预览中的内容吗?
发布于 2011-07-05 04:18:21
通过预览,我假设您谈论的是图像选择器界面(而不是关闭图像选择器界面后出现的默认预览屏幕)。
应用于图像拾取器界面(使用cameraViewTransform)的变换不会反映在拍摄的图像上。例如,如果尝试缩放(放大和缩小)应用缩放,则需要对获取的图像应用相同的(变换),以便使图像拾取器界面中的图像与实际保存的图像保持同步。
此外,在应用变换时,还必须考虑图像方向。
发布于 2011-07-04 14:57:35
从picker获得图像对象后,调整图像大小,然后裁剪
我需要做同样的事情-在我的例子中,选择适合缩放后的尺寸,然后裁剪每一端以适合其余的宽度。(我工作的是风景,所以可能没有注意到肖像模式的任何缺陷。)这是我的代码--它是UIImage上一个类别的一部分。在我的代码中,目标大小总是设置为设备的全屏大小。
@implementation UIImage (Extras)
#pragma mark -
#pragma mark Scale and crop image
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
UIImage *sourceImage = self;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
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);
if (CGSizeEqualToSize(imageSize, targetSize) == NO)
{
CGFloat widthFactor = targetWidth / width;
CGFloat heightFactor = targetHeight / height;
if (widthFactor > heightFactor)
scaleFactor = widthFactor; // scale to fit height
else
scaleFactor = heightFactor; // scale to fit width
scaledWidth = width * scaleFactor;
scaledHeight = height * scaleFactor;
// center the image
if (widthFactor > heightFactor)
{
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
}
else
if (widthFactor < heightFactor)
{
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
UIGraphicsBeginImageContext(targetSize); // this will crop
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width = scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil)
NSLog(@"could not scale image");
//pop the context to get back to the default
UIGraphicsEndImageContext();
return newImage;
}
https://stackoverflow.com/questions/6573015
复制相似问题