从UIImagePicker获取14 MB图像是否正常?(Is it normal to get 14 MB images from UIImagePicker?)

编程入门 行业动态 更新时间:2024-10-14 00:31:55
从UIImagePicker获取14 MB图像是否正常?(Is it normal to get 14 MB images from UIImagePicker?)

我正在开发一个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的图像是正常的吗?

我应该在将它们发送到服务器之前尝试压缩它们吗? 这里的常用方法是什么?

I am developing an iOS app which gets images from the camera with UIImagePickerController. Here is my code;

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) } }

I realized the image sizes are higher than I would expect (14 MB). I need to send the images to my server. My questions are;

Is it normal to have 14 MB images?

Should I attempt to compress them before I send them to my server? What is the common approach here?

最满意答案

第一个问题:

对于8 MP图像来说,这是绝对正常的。 请记住,如果您从图库中拍摄图像,则用户可以选择更大的图像(如果他/她已将图像存储在设备上)。

第二:

始终建议压缩图像。 但在你的情况下,我认为你已经使用相应的方法将其压缩为JPEGPNG

无论如何,如果您没有任何服务器限制,上传这样的图像是完全正常的。 没有任何无损方法可以进一步缩小尺寸。

一种是缩小图像,如果您不需要完整的8 MP分辨率,这可能是合适的。 另一种是限制调色板(256色或更少),但这会导致质量和细节的大量损失。 这只会使PNG或JPEG的压缩算法更容易完成它们的工作。

First question:

That's absolutely normal for an 8 MP image. Keep in mind that if you take an image from the gallery, the user can pick even bigger images if she/he have stored them on the device.

Second:

It is always recommended to compress images. But in your case i think you already compressed it to JPEG or PNG with the corresponding methods.

Anyway upload such an image is totally fine if you don't have any server restrictions. There is no lossless method to shrink the size any further.

One is to scale the image down which may be appropriate if you don't need the full 8 MP resolution. The other is to limit the color palettes (256 colors or less) but this will result in massive loss in quality and detail. This will only make it easier for the compression algorithms of PNG or JPEG to do their work.

更多推荐

本文发布于:2023-08-05 21:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437681.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   UIImagePicker   MB   images   normal

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!