Skip to content

Commit

Permalink
a few fixes for QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Feb 1, 2024
1 parent 57e96aa commit 7b66a9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Tinodios/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2316,8 +2316,9 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wXw-YX-QGk" userLabel="Copy">
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wXw-YX-QGk" userLabel="Copy">
<rect key="frame" x="313.66666666666669" y="0.0" width="27.333333333333314" height="44"/>
<color key="tintColor" systemColor="secondaryLabelColor"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal">
<imageReference key="image" image="doc.on.doc" catalog="system" symbolScale="large"/>
Expand All @@ -2326,8 +2327,9 @@
<action selector="copyTopicID:" destination="ZxW-bT-ZdQ" eventType="touchUpInside" id="0GK-gY-5xc"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aTy-DZ-Bk9" userLabel="QRCode">
<button opaque="NO" contentMode="scaleAspectFit" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aTy-DZ-Bk9" userLabel="QRCode">
<rect key="frame" x="349" y="0.0" width="25" height="44"/>
<color key="tintColor" systemColor="secondaryLabelColor"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal">
<imageReference key="image" image="qrcode" catalog="system" symbolScale="large"/>
Expand Down
18 changes: 10 additions & 8 deletions Tinodios/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ public class Utils {

public static func generateQRCode(from string: String) -> UIImage? {
let data = string.data(using: String.Encoding.ascii)
guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil }

if let filter = CIFilter(name: "CIQRCodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
let transform = CGAffineTransform(scaleX: 3, y: 3)
filter.setValue(data, forKey: "inputMessage")

if let output = filter.outputImage?.transformed(by: transform) {
return UIImage(ciImage: output)
}
}
guard let qrcode = filter.outputImage else { return nil }

return nil
// QR code is very small. Scaling it up without smoothing.
let scaledImageSize = qrcode.extent.size.applying(CGAffineTransform(scaleX: 3, y: 3))
UIGraphicsBeginImageContext(scaledImageSize)
let scaledContext = UIGraphicsGetCurrentContext()!
scaledContext.interpolationQuality = .none
UIImage(ciImage: qrcode).draw(in: CGRect(origin: .zero, size: scaledImageSize))
return UIGraphicsGetImageFromCurrentImageContext()!
}
}

Expand Down

0 comments on commit 7b66a9c

Please # to comment.