[英]Reduce image size without changing the dimensions programmatically in iphone
有没有人如何在不改变图像尺寸的情况下在 iphone 中以编程方式减小图像尺寸?
// 我知道有 3 种方式。
// 1. 使用just resize
UIImageView *iView = ...;
CGRect orgFrame = iView.frame;
iView.contentMode = UIViewContentModeScaleAspectFit;
iView.frame = CGRectMake(CGRectGetMinX(orgFrame), CGRectGetMinY(orgFrame),
CGRectGetWidth(orgFrame)*.5, CGRectGetHeight(orgFrame)*.5);
// 2. 使用 affineTransform 仅用于显示。
// 它使用 3x3 矩阵进行缩放。
// UIView 有
@property(nonatomic) CGAffineTransform transform
// 用法:
UIImageView *iView = ...;
iView.transform = CGAffineTransform(.5f, .5f);
// ==> will display 1/2 size view.
// 3. 使用 CALayer renderInContext: 获取缩小图像
UIImage *sourceImage = ...;
CGSize *reducedSize = CGSizeMake(CGRectGetWidth(sourceImage.frame)*.5f, CGRectGetHeight(sourceImage.frame)*.5f);
UIImage *reducedImage; {
UIImageView *imageView = [UIImageView initWithImage:sourceImage];
UIGraphicsBeginImageContext(reducedSize);
imageView.transform = CGAffineTransform(.5f, .5f);
[imageView renderInContext:UIGraphicsGetCurrentContext()];
reduceImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.