Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 501
Rohan Mishra Avatar asked Jul 11 '15 14:07

Rohan Mishra


People also ask

Can you print a snap code?

You can publicize your Snapcode on the web, social media, and print.

What are Snapcodes on Snapchat?

A Snapcode is a unique code you can scan to access features or unique content on Snapchat. Each Lens created in Lens Studio generates its own Snapcode that can be unlocked by people everywhere.

How do you get a QR code for Snapchat?

To use the feature, open “Settings” and select “Snapcodes,” then “Create Snapcode.” Enter the URL, add an image from the website or your phone, resize it so it fits inside the Snapchat ghost logo and then you can save it for use wherever.


1 Answers

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
}
like image 89
henrique Avatar answered Oct 05 '22 22:10

henrique