9

I am trying to generate a QR code that has a logo in the middle, as it is: enter image description here.

I am using a code I found here, my code is:

func generateQrCode(message: String!) -> CIImage! {

    var data = message.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)

    var filter: CIFilter = CIFilter(name: "CIQRCodeGenerator")
    filter.setValue(data, forKey: "inputMessage")
    filter.setValue("H", forKey: "inputCorrectionLevel")

    return filter.outputImage
}

How could adapt the code to generate a QR with a custom logo in the middle?

Community
  • 1
  • 1
Rodrigo Moreno
  • 629
  • 9
  • 24
  • Did you find the solution? How can we add custom image in the middle. – Salman Ali Apr 11 '18 at 10:38
  • I'm more interested in how they went about converting the default square output into all those rounded dots. Anyone got an idea on that? – Mudlabs Aug 13 '18 at 22:56

1 Answers1

10

Just overlay the middle part with the logo. The QR spec isn't going to some version that has a logo in the middle. The logo is just garbage that the error handling of the QR code reader handles. You don't want to make the logo too big, or else it won't be readable because of too many errors.

http://en.wikipedia.org/wiki/QR_code#Error_correction

bryan
  • 798
  • 7
  • 18
  • thanks for the explanation but you know how to build this code or any source code – jaskiratjd Oct 19 '16 at 12:44
  • 3
    @jaskiratjd you do not need to put any code. Simply add the logo in storyboard or programmatically center it to your QR code. QR codes are "readable when damaged" so a QR code can be read even if you place a logo in the middle. Perhaps read the following: https://www.david-steuber.com/2015/05/placing-a-logo-image-inside-a-qr-code/ – Jason Fel Nov 11 '16 at 14:23