QR Code Generator
Overview
Usage
import totalcross.qrcode.QRCode;
import totalcross.sys.Settings;
import totalcross.ui.Container;
import totalcross.ui.Control;
import totalcross.ui.ImageControl;
import totalcross.ui.Label;
import totalcross.ui.ScrollContainer;
import totalcross.ui.image.Image;
import totalcross.ui.image.ImageException;
import totalcross.util.UnitsConverter;
public class SampleQRCodeView extends ScrollContainer{
private String text;
public void initUI(){
text = new String ("I am a QRCode :)");
QRCode.DEBUG = true;
addCard(this, text);
}
private Image getImage (String text, int size){
Image image = new QRCode().generate(QRCode.ECC_QUARTILE, text);
try{
image = image.getScaledInstance(size, size);
}catch(ImageException e){
e.printStackTrace();
}
return image;
}
private void addCard (Container container, String text){
int size = (int)(Math.min(Settings.screenWidth, Settings.screenHeight) * 0.8);
Image image = getImage(text, size);
Label label = new Label(text);
label.autoSplit = true;
container.add(label, CENTER, TOP, Control.PARENTSIZE, Control.PREFERRED);
container.add(new ImageControl(image), Control.CENTER, Control.AFTER + UnitsConverter.toPixels(Control.DP + 30), size, size);
}
}
Error Correction Level
References
Last updated
Was this helpful?