我正在开发一个iOS应用程序,它使用UIImagePickerController
从相机获取图像。这是我的代码;
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!){
imageTaken = image
self.dismissViewControllerAnimated(true, completion: nil)
self.performSegueWithIdentifier("camera", sender: self)
}
@IBAction func cameraButtonPressed(sender: UIBarButtonItem) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
var imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.mediaTypes = NSArray(object: kUTTypeImage)
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
else{
imageTaken = UIImage(named: "potato")
self.performSegueWithIdentifier("camera", sender: self)
}
}
我意识到图像尺寸比我预期的要高(14 MB)。我需要将图像发送到我的服务器。我的问题是;
拥有14 MB图像是否正常?
我应该在将它们发送到服务器之前尝试压缩吗?这里的常用方法是什么?
答案 0 :(得分:0)
这对于8 MP图像来说绝对正常。请记住,如果您从图库中拍摄图像,用户可以选择更大的图像,如果他/她已将图像存储在设备上。
始终建议压缩图像。但在你的情况下,我认为你已经用相应的方法将它压缩为 JPEG 或 PNG 。
如果您没有任何服务器限制,无论如何上传这样的图像都是完全正常的 没有任何无损方法可以进一步缩小尺寸。
一种是缩小图像,如果您不需要完整的8 MP分辨率,这可能是合适的 另一种是限制调色板(256色或更少),但这会导致质量和细节的大量损失。这只会使PNG或JPEG的压缩算法更容易完成它们的工作。