0
我有一段代碼利用ImageIO
庫來調整圖像的大小,使其在上傳到Parse時變得更小。上傳時,圖片逆時針旋轉45度。調整大小後旋轉45度的圖像數據
let imageBytes = UIImageJPEGRepresentation(imageView.image, 1.0)
let size = CGSizeMake(1024, 1024)
if let imageSource = CGImageSourceCreateWithData(imageBytes, nil) {
let options: [NSString: AnyObject] = [
kCGImageSourceThumbnailMaxPixelSize: NSNumber(double: Double(max(size.width, size.height))/2.0),
kCGImageSourceCreateThumbnailFromImageIfAbsent: true,
kCGImageSourceCreateThumbnailWithTransform: false
]
//2. Recreate the Image that has been scaled
let scaledImage = UIImage(CGImage: CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options))
let scaledImageBytes = UIImageJPEGRepresentation(scaledImage, 1.0)
let metaData = [
"imageBytes": scaledImageBytes, //for some reason, scaledImageBytes causes a 90 degree rotation on the picture. Using unscaled image for now.
]
//3. upload the image to Parse
PFCloud.callFunctionInBackground("uploadImage", withParameters: metaData) { message, error in
if let error = error {
println("error uploading: \(error)")
} else if let message = message as? String {
println("success: \(message)")
}
}
}
我該如何解決這個問題?