2011-11-09 108 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(); 
    }