我正在嘗試顯示 QR 碼,SwiftUI
但一旦 QR 碼的大小增加,它就會變得非常模糊。此外,當我導航到QRcode view
顯示的螢屏時會有輕微延遲,不確定這是否是性能問題。
我得到一個日志說
The filter 'CIPortraitEffectSpillCorrection' is not implemented in the bundle at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/CoreImage/PortraitFilters.cifilter.
下面是我如何使用 SwiftUI 實作 QR 碼視圖的代碼
struct SampleView: View {
let qrWidth = UIScreen.screenWidth / 2
let context = CIContext()
let filter = CIFilter.qrCodeGenerator()
func generateQRCode(from string: String) -> UIImage {
filter.message = Data(string.utf8)
if let outputImage = filter.outputImage {
if let cgimg = context.createCGImage(outputImage, from: outputImage.extent) {
return UIImage(cgImage: cgimg)
}
}
return UIImage(systemName: "xmark.circle") ?? UIImage()
}
var body: some View {
stack(alignment: .leading){
if let qrImage = generateQRCode(from: "https://www.hackingwithswift.com/books/ios-swiftui/generating-and-scaling-up-a-qr-code") {
Image(uiImage: qrImage)
.resizable()
.scaledToFit()
.frame(width: qrWidth,height: qrWidth)
} else {
Text("Error")
}
}.frame(maxWidth: .infinity,maxHeight: .infinity,alignment: .top)
.padding().background(Constants.WHITE_COLOR)
}
}
uj5u.com熱心網友回復:
嘗試添加
.interpolation(.none)
到影像。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/530622.html
標籤:IOS迅速迅捷