我有一個應用程序,從相機拍攝圖片並將其放入UIImageView中。之後,你可以添加小的「剪貼畫」圖片,它被添加爲UIImageView(我的代碼中的tempImageView)的子視圖。如何將UIImageView與子視圖保存到相機膠捲?
但是,當我嘗試通過tempImageView.image將圖像保存到相機時,圖像變得更大,並且添加到它的子視圖也不會出現。任何想法如何將UIImageView與我的子視圖保存到相機膠捲?
這是我如何保存圖像:
@IBAction func saveImageButtonPressed(sender: UIButton) {
UIImageWriteToSavedPhotosAlbum(tempImageView.image!, self, "image:didFinishSavingWithError:contextInfo:", nil)
}
func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Your altered image has been saved to your photos.", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
} else {
let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
}
}
這裏是我如何將圖片添加到我的tempImageView:
@IBAction func berlockButtonPressed(sender: UIButton) {
let imageName = "berlock.png"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 200, y: 200, width: 60, height: 100)
tempImageView.addSubview(imageView)
}
感謝您的幫助。
非常感謝!這樣做的伎倆,如果有人想知道我也不需要重複我的tempImageViews子視圖。 – nullforlife