我要将编辑过的图片分享给社交形象。目前,我使用0.png作为输出图像。
现在,如何将0.png替换为已编辑的图像并进行共享?
import UIKit
import Social
class EditController: UIViewController {
var image:UIImage?
var index:Int?
@IBOutlet weak var photo: UIImageView!
let context = CIContext(options: nil)
override func viewDidLoad() {
super.viewDidLoad()
self.photo.image = self.image
}
@IBAction func applyFilter(sender: UIBarButtonItem) {
print("applyFilter")
let beginImage = CIImage(image: self.image!)
let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314)) / 100)]
let filteredImage = beginImage!.imageByApplyingFilter("CIHueAdjust", withInputParameters: randomColor)
let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent)
self.image = UIImage(CGImage: renderedImage)
self.photo.image = self.image
}
@IBAction func shareToFacebook(sender: AnyObject) {
let shareToFacebook : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
shareToFacebook.setInitialText("Hello I Posted Using Swift And Social Framework")
shareToFacebook.addImage(UIImage(named: "0.png"))
self.presentViewController(shareToFacebook, animated: true, completion: nil)
}
}
答案 0 :(得分:0)
@IBAction func shareToTwitter() {
var shareToTwitter : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
shareToTwitter.setInitialText("Hello World")
shareToTwitter.addImage(UIImage(named: "32.png"))
self.presentViewController(shareToTwitter, animated: true, completion: nil)
}
信用:
更多教程:
答案 1 :(得分:0)
OP在其提问的评论中回答:
我通过将
UIImage(named: "0.png")
替换为self.image
来修复它。