mhnds

Untitled

Oct 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public class QRCode extends AppCompatActivity {
  2.  
  3. EditText txtInput;
  4. Button btnCreateBarcode;
  5. ImageView imgBarcode;
  6. String text2Qr;
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.activity_qrcode);
  11. txtInput = (EditText) findViewById(R.id.txtInput);
  12. btnCreateBarcode = (Button) findViewById(R.id.btnCreateBarcode);
  13. imgBarcode = (ImageView) findViewById(R.id.imgBarcode);
  14. btnCreateBarcode.setOnClickListener(new View.OnClickListener() {
  15. @Override
  16.  
  17. public void onClick(View view) {
  18. text2Qr = txtInput.getText().toString().trim();
  19. MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
  20. try {
  21. BitMatrix bitMatrix = multiFormatWriter.encode(text2Qr, BarcodeFormat.QR_CODE, 200, 200);
  22. BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
  23. Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
  24. imgBarcode.setImageBitmap(bitmap);
  25. }
  26. catch (WriterException e) {
  27. e.printStackTrace();
  28. }
  29.  
  30. }
  31. });
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment