2010-12-23 58 views
0

我有以下代码来保存图像,但它质量似乎很差...帮助保存图像

有没有什么办法让图像质量好?

感谢所有帮助

UIGraphicsBeginImageContext(CGSizeMake(self.view.bounds.size.width, 
                self.view.bounds.size.height-50)); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextTranslateCTM(context, 0, -50);  
[self.view.layer renderInContext:context]; 
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
NSData* imageData = [NSData dataWithData:UIImageJPEGRepresentation(viewImage,0)]; 

回答

2

想到的第一件事就是UIImageJPEGRepresentation函数的压缩质量参数 - 将其设置为最低的质量(0.0),试图将其设置为最大质量值:

NSData* imageData = [NSData dataWithData:UIImageJPEGRepresentation(viewImage,1.0)]; 
0

弗拉基米尔的答案中提到了一个选项。另一种选择是你可以使用UIImagePNGRepresentation。它将使用PNG格式。