I am trying to execute the Code128 tutorial according to this website: http://www.onbarcode.com/products/android_barcode/barcodes/code_128.html, but I have no idea how to display the barcode.
Here is the Java code:
public class MainActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView2);
class Test extends View {
public Test(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Code128 barcode = new Code128();
barcode.setData("112233445566");
barcode.setProcessTilde(false);
barcode.setUom(IBarcode.UOM_PIXEL);
barcode.setX(1f);
barcode.setY(75f);
barcode.setLeftMargin(10f);
barcode.setRightMargin(10f);
barcode.setTopMargin(10f);
barcode.setBottomMargin(10f);
barcode.setResolution(72);
barcode.setShowText(true);
barcode.setTextFont(new AndroidFont("Arial", Typeface.NORMAL, 12));
barcode.setTextMargin(6);
barcode.setTextColor(AndroidColor.black);
barcode.setForeColor(AndroidColor.black);
barcode.setBackColor(AndroidColor.white);
RectF bounds = new RectF(30, 30, 0, 120);
try {
barcode.drawBarcode(canvas, bounds);
// imageView.setImageBitmap(barcode);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
What method should I use to display the barcode?