-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from ajamaica/feature/qrcode_helper
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// QRCodeHelper.swift | ||
// | ||
// | ||
// Created by Arturo Jamaica on 2022/02/20. | ||
// | ||
#if canImport(UIKit) | ||
#if canImport(CoreImage) | ||
import Foundation | ||
import UIKit | ||
import CoreImage | ||
|
||
class QRCodeHelper { | ||
func generateQRCode(from url: URL) -> UIImage? { | ||
let data = url.absoluteString.data(using: String.Encoding.ascii) | ||
|
||
if let filter = CIFilter(name: "CIQRCodeGenerator") { | ||
filter.setValue(data, forKey: "inputMessage") | ||
let transform = CGAffineTransform(scaleX: 3, y: 3) | ||
|
||
if let output = filter.outputImage?.transformed(by: transform) { | ||
return UIImage(ciImage: output) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
#endif | ||
#endif |