新生成的图像质量低ios迅速

我一直在使用在线教程制作简单的照片应用程序。 我做了上传或捕获图像的应用程序,并可以在图像上添加文本并保存。 但问题是保存的图像质量很低。 它也采取了应用程序的button和酒吧的输出图像了。

这是我如何产生最终的形象

func save() { //Create the meme var meme = Meme( textField: topTextField.text!,textField2: bottomTextField.text!, image: imageView.image, memedImage: memedImage) } func generateMemedImage() -> UIImage { // Render view to an image save() UIGraphicsBeginImageContext(self.view.frame.size) self.view.drawViewHierarchyInRect(self.view.frame, afterScreenUpdates: true) memedImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return memedImage } @IBAction func saveImage(sender: AnyObject) { generateMemedImage() UIImageWriteToSavedPhotosAlbum(memedImage, nil, nil, nil) } 

有无论如何要做到这一点与质量输出?

你不是调整方面的大小,你也需要调整视网膜大小
用这个:

 private func _resizeWithAspect_doResize(image: UIImage,size: CGSize)->UIImage{ if UIScreen.mainScreen().respondsToSelector("scale"){ UIGraphicsBeginImageContextWithOptions(size,false,UIScreen.mainScreen().scale); } else { UIGraphicsBeginImageContext(size); } image.drawInRect(CGRectMake(0, 0, size.width, size.height)); var newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } func resizeImageWithAspect(image: UIImage,scaledToMaxWidth width:CGFloat,maxHeight height :CGFloat)->UIImage { let oldWidth = image.size.width; let oldHeight = image.size.height; let scaleFactor = (oldWidth > oldHeight) ? width / oldWidth : height / oldHeight; let newHeight = oldHeight * scaleFactor; let newWidth = oldWidth * scaleFactor; let newSize = CGSizeMake(newWidth, newHeight); return self._resizeWithAspect_doResize(image, size: newSize); } 

使用:

  var image : UIImage = yourImageClassInstance.resizeImageWithAspect(image:UIImage(named: "yourImg"),scaledToMaxWidth: 35.0, maxHeight: 45.0);