Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
@IBAction func pushImmageButton(_ sender: Any) {
let ciFilter = CIFilter(name: "CIQRCodeGenerator")
let baseUrlString=""
let qrString = baseUrlString+textField.text!
let data = String.Encoding.utf8)
ciFilter?.setValue(data, forKey: "inputMessage")
ciFilter?.setValue("L", forKey: "inputCorrectionLevel")
let ciContext = CIContext()
let sizeTransform = CGAffineTransform(scaleX: 4, y: 4)
let cgimg = ciContext.createCGImage((ciFilter?.outputImage)!, from: (ciFilter?.outputImage?.extent)!)
let qrcodeImage: CIImage = (ciFilter?.outputImage!.transformed(by: sizeTransform))!
// CIImageからUIImageに変換する
let imageContext = CIContext(options:nil)
let temp:CGImage = imageContext.createCGImage(qrcodeImage, from: qrcodeImage.extent)!
let ret = UIImage(cgImage: temp)
// ファイルパスを指定する
var imagePath: String {
let doc = NSSearchPathForDirectoriesInDomains( .documentDirectory, .userDomainMask, true )[0] as String
return ( doc as NSString ).appendingPathComponent("qr_send.jpg" )
// 指定したファイルパスに保存する
let senddata: NSData = ret.jpegData(compressionQuality: 0.9) as! NSData
senddata.write( toFile: imagePath, atomically: true )
let transferFile: NSURL = NSURL( fileURLWithPath: imagePath )
wcSession.transferFile( transferFile as URL, metadata: )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.