How can I generate an image that will be similar to Snapchat's Snapcode and will be used in the same way?
Asked Answered
B

1

15

I'm building an app that uses a QR Code to connect users, similar to how Snapchat allows users to add each other on Snapchat.

I was hoping to use a more aesthetically pleasing alternative to the QR Code, something similar to Snapchat's Snapcode. Any idea as to how it can be done in an iOS application?

Balanchine answered 11/7, 2015 at 14:29 Comment(6)
Just checking in on how this went. Did you succeed in making something more similar to snapcode than using the solution below?Quarterly
Hi Rohan did you get solution on this i want to build the same.Wick
Did you find anything Rohan ?Anastaciaanastas
@RakshitSoni :did you guys found solution?Gnosticize
@hyd : did you guys found solution?Gnosticize
@FahimParkar Not yet bro. let me know here if u found one :)Anastaciaanastas
T
3

If you don't want to use QRCode at all you'll have to create your own pattern to generate/reading the image.

But maybe you can use QRCode.

QRCode has an error correction level. Considering it you can still make your QRCode more aesthetically pleasing as you asked for. Just keep in mind "The higher the error correction level, the less storage capacity" and you can customize your image as long as the algorithm can get the info you need.

When you're generating the QRCode image you can do it like this:

Swift 3.1

private enum InputCorrectionLevel: String {
    case low = "L" // 7%
    case medium = "M" // 15%
    case high = "Q" // 25%
    case ultra = "H" // 30%
}

private enum QRCodeGenerationError {
    case initializingFilter
    case applyingFilter
}

func qrCode(from string: String, withSize frameSize: CGSize) throws -> CIImage {
    guard let filter = CIFilter(name: "CIQRCodeGenerator") else {
        throw QRCodeGenerationError.initializingFilter
    }

    let data = string.data(using: .isoLatin1, allowLossyConversion: false)
    filter.setValue(data, forKey: "inputMessage")
    filter.setValue(InputCorrectionLevel.low.rawValue, forKey: "inputCorrectionLevel")

    guard let outputImage = filter.outputImage else {
        throw QRCodeGenerationError.applyingFilter
    }

    let scaleX = frameSize.width / outputImage.extent.size.width
    let scaleY = frameSize.height / outputImage.extent.size.height
    let qrCodeCIImage = outputImage.applying(CGAffineTransform(scaleX: scaleX, y: scaleY))
    return qrCodeCIImage
}
Thought answered 24/2, 2016 at 19:4 Comment(1)
This is essentially the correct answer. Emphasis on the first part of the answer: one would have to generate their own image and reader for said image to accomplish a Snapchat-esque QR Code.Balanchine

© 2022 - 2024 — McMap. All rights reserved.