我正在从事室内装饰应用,我们可以在相机屏幕上添加沙发,桌子,椅子台灯,然后可以通过触摸缩放UIImage缩放图片。但是通过缩放我们不想将UIImage尺寸增加到320 x 480以上,我的意思是想限制在iphone Boundary中。
任何建议,我已经实施并尝试过,但无法得到确切的解决方案。我用来检查中心的基础,但这种方法不起作用,想要一些像边缘检测这样的东西可能是精确的解决方案,
已经感谢,期待
这是我用来调整UIImageView
的一些代码-(BOOL)isValidSizeForView:(UIView *)myView forSize:(CGSize)size
{
BOOL Decision = NO;
CGRect rect = myView.frame;
CGRect BoundRect = CGRectMake(0, 0, 320, 480);
float MinX = (BoundRect.origin.x+(myView.frame.size.width/2));
float MaxX = ((BoundRect.origin.x+BoundRect.size.width)-(myView.frame.size.width/2));
float MinY = (BoundRect.origin.y+(myView.frame.size.height/2));
float MaxY = ((BoundRect.origin.y+BoundRect.size.height)-(myView.frame.size.height/2));
if(rect.origin.x > MinX && rect.origin.x< MaxX && rect.origin.y> MinY && rect.origin.y<MaxY)
{
Decision = YES;
}
else
{
printf(":( no sorry \n");
}
return Decision;
}
答案 0 :(得分:0)
您可以通过执行以下操作获得图像的最大缩放尺寸:
- (CGSize)zoomedSizeForImage:(UIImage *)image constrainedTo:(CGSize)maxSize {
CGFloat width = image.size.width;
CGFloat height = image.size.height;
if (width > maxSize.width) {
width = maxSize.width;
height = height * maxSize.width / width;
}
if (height > maxSize.height) {
width = width * maxSize.height / height;
height = maxSize.height;
}
return CGSizeMake(width, height);
}