import android.graphics.Bitmap;
import android.graphics.Color;
public class CodeCreater128C {
/** * 生成Code128C格式条形码(纯数字,偶数位长度) * *@param content 条码内容(偶数位纯数字内容) *@param widthScale(1-10, 默认2,) *@param height 条码高度(40-200,默认100) *@return */
public static Bitmap create128CBitmap(String content, int widthScale, int height) {
if (content == null || content.length() == 0) {
return null;
}
if (height<40||height>200) {
height = 100;
}
if ((content.length() % 2) == 1) {
return null;
}
for (int i = 0; i < content.length(); i++) {
char charFlag = content.charAt(i);
if (charFlag > 57 || charFlag < 48) {
return null;
}
}
String text = CodeSymbol128C.SYMBOL_START_C.getSymbolValue(); // 获取开始位
int examine = 105;
int count = 0;
while (content.length() != 0) {
int tempValue = Integer.valueOf(content.subSequence(0, 2).toString());
text += CodeSymbol128C.getTargetSymbolValue(tempValue);
examine += tempValue * ++count;
content = content.substring(2);
}
examine = examine % 103; // 获得严效位
text += CodeSymbol128C.getTargetSymbolValue(examine); // 获取严效位
text += CodeSymbol128C.SYMBOL_STOP.getSymbolValue(); // 结束位
return getImageFrom128CSy