当我将导入图像[其他图像]发送到服务器的时间少于iphone图像[通过默认相机拍摄图像时]。是否可以选择调整图像大小而不损失其质量?调整图像的质量而不损失其质量
2
A
回答
3
使用此代码,这将有助于
+ (UIImage *)scaleImage:(UIImage *)image maxWidth:(int) maxWidth maxHeight:(int) maxHeight
{
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
if (width <= maxWidth && height <= maxHeight)
{
return image;
}
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
if (width > maxWidth || height > maxHeight)
{
CGFloat ratio = width/height;
if (ratio > 1)
{
bounds.size.width = maxWidth;
bounds.size.height = bounds.size.width/ratio;
}
else
{
bounds.size.height = maxHeight;
bounds.size.width = bounds.size.height * ratio;
}
}
CGFloat scaleRatio = bounds.size.width/width;
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextTranslateCTM(context, 0, -height);
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
2
试试这个方法波纹管...
呼叫像波纹管......
UIImage *imgBig = [self imageWithImage:yourImage scaledToSize::yourNewImageSize];
,并使用此方法波纹管..
-(UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
UIGraphicsBeginImageContextWithOptions(newSize, YES, image.scale);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
+0
如果我想保留图像质量,应该是新的图像大小? –
+0
您可以使用图像的原始尺寸将0.5(图像的一半尺寸)值与尺寸一起设置,以保持图像质量。 –
相关问题
- 1. 调整图片质量而不损失
- 2. 调整位图而不损失质量
- 3. 使用rmagick在rails上调整ruby图像的质量而不损失质量
- 4. 如何调整图像的大小而不损失质量
- 5. 调整图像的大小而不损失质量与Gimp
- 6. 当图像较大时调整图像的质量而不会丢失质量
- 7. 图像质量损失
- 8. 图像质量损失
- 9. 在android中减少图像大小而不损失其质量
- 10. 图像调整UpScale丢失质量
- 11. UIView中的损失质量图像
- 12. 调整图像大小而不损失质量的最佳方法是什么?
- 13. Android - 位图质量损失?
- 14. 重新调整图像的大小而不会丢失质量
- 15. 图像大小调整没有质量损失?
- 16. 在ASP.NET中调整图像质量损失?
- 17. 在windowsphone xaml中调整图像大小(png)而不损失质量
- 18. 缩小img而不损失质量?
- 19. 画布缩小图像质量损失
- 20. 图像上传没有质量损失
- 21. 收缩图像质量损失
- 22. 缩小图像质量损失
- 23. 调整图像大小,而不会丢失质量
- 24. 缩放图像而不丢失质量
- 25. 调整大小,而不会丢失其质量iphone
- 26. 在C#中为asp.net调整图像大小时图像质量损失webform
- 27. 调整UILabel的质量不会造成损失
- 28. Qt调整图像的最佳质量
- 29. 的PageSpeed调整图像质量低
- 30. 调整后的图像质量下降
帮助?请详细说明你的问题你真的想要做什么 – amar
什么将是正确的图像的宽度和高度? – user2003416
我在查看它。 – user2003416