2011-11-09 105 views
2

我想生成彩色QR码。 我曾使用https://github.com/kuapay/iOS-QR-Code-Generator代码来生成QR码。 现在生成的qr码始终是黑色。我想使它成为红色或其他颜色。 着色的编码和QR码.png图像的绘制完成QR_Draw_png.mm文件。 我该怎么编辑QR_Draw_png.mm这个文件。 如何生成多彩的qr码。生成彩色QR码

这怎么可能。

请帮帮我。

+0

Hi Shweta,这是来自钦奈的Dinesh。我在我的应用程序中使用相同的kuapay。但它只适用于第一次。如果我尝试重新生成而不关闭应用程序。那么应用程序会自动崩溃。你能帮我么?谢谢 – dinesh

回答

1

这是产生丰富多彩的QR码最好的例子。

http://www.oscarsanderson.com/2013/08/12/implementing-a-qr-code-generator-on-the-iphone/

你会发现qrencode库从上面的链接,并UIImage的类别。

之后您需要使用您选择的颜色简单调用此方法来生成它。

mgView.image = [UIImage QRCodeGenerator:txtCouponName.text 
          andLightColour:[UIColor whiteColor] 
          andDarkColour:[UIColor blackColor] 
          andQuietZone:1 
           andSize:300]; 
+0

虽然此链接可能会回答问题,但最好在此包含答案的重要部分,提供链接供参考。如果链接页面更改,则仅链接答案可能会失效。 – bartektartanus

+0

@bartektartanus是的,让我更新.. –

0
 QRCodeWriter writer = new QRCodeWriter(); 
    try { 
     BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512); 
     int width = bitMatrix.getWidth(); 
     int height = bitMatrix.getHeight(); 
     Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); 
     for (int x = 0; x < width; x++) { 
      for (int y = 0; y < height; y++) { 
// set colors for QR code 
       bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE); 
      } 
     } 
     ((ImageView) findViewById(R.id.img_result_qr)).setImageBitmap(bmp); 

    } catch (WriterException e) { 
     e.printStackTrace(); 
    }