Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class QRCode extends AppCompatActivity {
- EditText txtInput;
- Button btnCreateBarcode;
- ImageView imgBarcode;
- String text2Qr;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_qrcode);
- txtInput = (EditText) findViewById(R.id.txtInput);
- btnCreateBarcode = (Button) findViewById(R.id.btnCreateBarcode);
- imgBarcode = (ImageView) findViewById(R.id.imgBarcode);
- btnCreateBarcode.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- text2Qr = txtInput.getText().toString().trim();
- MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
- try {
- BitMatrix bitMatrix = multiFormatWriter.encode(text2Qr, BarcodeFormat.QR_CODE, 200, 200);
- BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
- Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
- imgBarcode.setImageBitmap(bitmap);
- }
- catch (WriterException e) {
- e.printStackTrace();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment