爲什麼我在我的iPhone上拍攝的一些圖片太大而無法作爲PFFile進行解析。限制是10毫克,我知道這些照片不能那麼大。有些很小,但大多數不是。無論如何要優化分析的大小?這裏是我的代碼分析和快速PFFile大小問題
//--CONTROLS HOW TO PICK THE IMAGE WHEN THIS BUTTON IS CLICKED--\\
@IBAction func chooseImage(sender: AnyObject) {
var image = UIImagePickerController()
image.delegate = self
image.navigationBar.tintColor = UIColor.whiteColor()
image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
image.allowsEditing = false
self.presentViewController(image, animated: true, completion: nil)
}
@IBAction func postImage(sender: AnyObject) {
self.view.endEditing(true)
var error = ""
if photoSelected == false{
error="Please select an image to post."
}
else if contactText.text == ""{
error = "Please enter an email or phone number."
}
else if nameOfPost.text == ""{
error="Please enter the name of the post."
}
else if descriptionOfPost.text == ""{
error="Please enter a description about your posts."
}
if error != ""{
displayAlert("Oops! There was an error with posting.", error: error)
}
else{
activityIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 125, 125))
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
activityIndicator.backgroundColor = UIColor(red: (158/255.0), green: (40/255.0), blue: (52/255.0), alpha: 1)
activityIndicator.layer.cornerRadius = 10
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.sharedApplication().beginIgnoringInteractionEvents()
//--MAIN CODE TO POST--\\
var post = PFObject(className: "Posts")
post["Contact"] = contactText.text
post["Name"] = nameOfPost.text
post["Description"] = descriptionOfPost.text
let imageData = UIImagePNGRepresentation(self.imageToPost.image)
let imageFile = PFFile(name: "image.png", data: imageData)
post["imageFile"] = imageFile
post["createdBy"] = PFUser.currentUser()?.objectId
//--GETTING LOCATION OF THE POST--\\
PFGeoPoint.geoPointForCurrentLocationInBackground {
(geoPoint: PFGeoPoint?, error: NSError?) -> Void in
if error == nil {
post.setValue(geoPoint, forKey: "Location")
post.saveInBackground()
println("found location")
}
}
//--SAVING THE Post HERE--\\
post.saveInBackgroundWithBlock{(success:Bool, error:NSError?)-> Void in
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if success == false{
self.activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
self.displayAlert("Sorry! We could not post.", error: "Please try again later.")
}
//--NO ERRORS SO NOW WE CAN SAVE AND POST==\\
else{
self.performSegueWithIdentifier("backToFeed", sender: self)
}
}
}
}
我真正需要的是能拍照的我的應用程序,但每一個畫面,我從相機拍攝太大。
您可以在保存到Parse之前調整圖像大小。 –
我會如何去做這件事。這是用戶驅動的 – user2967062
https://www.google.com/search?client=safari&rls=zh-CN&q=resize+uiimage+ios&ie=UTF-8&oe=UTF-8#safe=off&q=resize+uiimage+ios+site:stackoverflow .com –