Iphone 调整大小后增强图像质量
有人能提出一些方法来提高图像的质量吗?把图像调整到更大的尺寸?Iphone 调整大小后增强图像质量,iphone,ios,image,resize,Iphone,Ios,Image,Resize,有人能提出一些方法来提高图像的质量吗?把图像调整到更大的尺寸? 调整大小时,生成的图像将像素化。我需要最大程度地减少像素化。您可以使用以下代码压缩或增加图像大小 CGFloat compression = 222.0f; CGFloat maxCompression = 202.1f; int maxFileSize = 160*165; //fill your size need NSData *imageDat = UIImageJPEGRepresentation(image.image
调整大小时,生成的图像将像素化。我需要最大程度地减少像素化。您可以使用以下代码压缩或增加图像大小
CGFloat compression = 222.0f;
CGFloat maxCompression = 202.1f;
int maxFileSize = 160*165; //fill your size need
NSData *imageDat = UIImageJPEGRepresentation(image.image, compression);
while ([imageDat length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1222;
imageDat = UIImageJPEGRepresentation(decodedimage.image, compression);
}
NSLog(@"image compressed success");
[image setImage:[UIImage imageWithData:imageDat]];
image1 = [self imageWithImage:image1 convertToSize:CGSizeMake(100, 100)];
// For convert the image to fix size
- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, 320,460)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
您可以使用以下代码压缩或增大图像的大小
CGFloat compression = 222.0f;
CGFloat maxCompression = 202.1f;
int maxFileSize = 160*165; //fill your size need
NSData *imageDat = UIImageJPEGRepresentation(image.image, compression);
while ([imageDat length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1222;
imageDat = UIImageJPEGRepresentation(decodedimage.image, compression);
}
NSLog(@"image compressed success");
[image setImage:[UIImage imageWithData:imageDat]];
image1 = [self imageWithImage:image1 convertToSize:CGSizeMake(100, 100)];
// For convert the image to fix size
- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, 320,460)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
有一篇文章叫:,你应该阅读并理解其中给出的每一个方面。我想它会回答你脑海中出现的每一个问题。我认为这是一篇漂亮的文章,具有适当的图形表示(意味着阅读时不那么枯燥)