android 에서 바코드 이미지를 생성하려면. zxing 라이브러리를 이용한다.
private void doCreateBarcode()
{
com.google.zxing.MultiFormatWriter zxingWriter = new MultiFormatWriter();
String sBarcode = "0000000000000000"; // 16자리 숫자
try
{
int w = 180; // 바코드 이미지 넓이
int h = 120; // 바코드 이미지 높이
BitMatrix bm = zxingWriter.encode(sBarcode, BarcodeFormat.CODE_128, w, h);
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
for(int i=0; i < w; i++) //width
{
for(int j=0; j < h; j++) //height
{
bitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK: Color.WHITE);
}
}
if(bitmap == null)
{
lib_common.doShowToast(this, "error");
return;
}
ivBarcode.setImageBitmap(bitmap);
}
catch(com.google.zxing.WriterException exp)
{
lib_common.doShowToast(this, "WriterException");
}
}
'Android 초보' 카테고리의 다른 글
AndroidStudio1.5.1 transformClassesWithDexForDebug 오류 (0) | 2016.02.12 |
---|---|
android. ssl. client certificate. 클라이언트 인증서. pinning (1) | 2016.02.02 |
HTTPS with Client Certificates on Android (0) | 2016.01.26 |
LocalBroadcastManager (0) | 2015.12.21 |
안드로이드. 바코드. zxing library (0) | 2015.12.15 |