我一直试图在安卓上使用Barcode4J,但我似乎无法获得BufferedImage类,我也不确定我应该如何用Android.graphic.*中的任何东西来替换这个类。此外,由于显而易见的原因,除了BufferedImage对象之外,Barcode4J不会接受任何其他对象。我可以用什么来代替,或者有没有更适合Android的条形码生成器库?
我尝试过Barcode4Android,这真的没有任何意义,因为他们在GIT上给出的示例使用的是java.awt.image.BufferedReader包中的BufferedImage,也是>.<。所以我又回到了第一步。
我实际上只需要QR生成函数。
我的问题。1.有没有安卓版Barcode4J的替代品?2.或者有没有办法解决我的问题?
下面是我尝试使用的Java教程之一
public class HelloExample1 {
public static void main(String[] args) throws Exception{
//Create the barcode bean
Code39Bean bean = new Code39Bean();
final int dpi = 150;
//Configure the barcode generator
bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar, width exactly one pixel
bean.setWideFactor(3);
bean.doQuietZone(false);
//Open output file
File outputFile = new File("resources"+"/"+"images"+"/"+"out.png");
OutputStream out = new FileOutputStream(outputFile);
try {
//Set up the canvas provider for monochrome PNG output
BitmapCanvasProvider canvas = new BitmapCanvasProvider(
out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
//Generate the barcode
bean.generateBarcode(canvas, "Hello World");
//Signal end of generation
canvas.finish();
} finally {
out.close();
}
}
}发布于 2016-05-06 20:51:07
试试Zxing,它是一个代码生成器和阅读器,很容易在安卓系统中使用。希望能有所帮助。
https://stackoverflow.com/questions/36514067
复制相似问题