#pragma mark - 压缩图片分辨率
-(UIImage *)scaleImage: (UIImage *)image{
// CGSize size = CGSizeMake(image.size.width * scaleFloat, image.size.height * scaleFloat);
//
// UIGraphicsBeginImageContext(size);
// CGContextRef context = UIGraphicsGetCurrentContext();
// CGAffineTransform transform = CGAffineTransformIdentity;
//
// transform = CGAffineTransformScale(transform, scaleFloat, scaleFloat);
// CGContextConcatCTM(context, transform);
//
// // Draw the image into the transformed context and return the image
// [image drawAtPoint:CGPointMake(0.0f, 0.0f)];
// UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
//
// return newimg;
// CGSize newSize = CGSizeMake(600, 600);
CGFloat scaleSize = 600;
CGFloat width = image.size.width;
CGFloat height = image.size.height;
if (width == 0 || height == 0){
return image;
}
if(width < scaleSize && height < scaleSize){
return image;
}
//压缩比例
CGFloat scaleFactor;
//图片长宽,数值大的压缩到600,剩下按长宽比压缩
if (width > height) {
scaleFactor = scaleSize / width;
}else{
scaleFactor = scaleSize / scaleSize;
}
CGFloat scaledWidth = width * scaleFactor;
CGFloat scaledHeight = height * scaleFactor;
CGSize targetSize = CGSizeMake(scaledWidth,scaledHeight);
UIGraphicsBeginImageContext(targetSize);
[image drawInRect:CGRectMake(0,0,scaledWidth,scaledHeight)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
压缩图片分辨率
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.情景展示 图片太大,如何实现无损压缩? 2.解决方案 压缩图片分为2种情况:情况一:原图片大小 <= 5MB最...
- 本文原创,欢迎转发,并在开头处表明作者:简书:数码视听娱乐 如今在视频领域、智能电视机领域,4K是一个非常热门的概...
- + (CGRect )scaleImage:(UIImage *)image toSize:(CGRect)new...