static WM_HMEM GetBarcodeImage(DATAFORMAT *Msg)
{
GUI_RECT ImageSize;
struct zint_symbol* my_symbol = ZBarcode_Create();
int fd;
U32 len;
int i;
U16 x1=0,y1=0;
char *barCodeData;
WM_HMEM hMem;
switch(Msg->GeneralPara0)
{
case 0:
my_symbol->symbology = BARCODE_CODE128;
break;
case 1:
my_symbol->symbology = BARCODE_EANX;
break;
case 2:
my_symbol->symbology = BARCODE_QRCODE;
break;
}
fd = ZBarcode_Encode(my_symbol,Msg->DispProp,0);
Msg->GeneralPara4 = my_symbol->rows;
len = my_symbol->rows*(1 + my_symbol->width);
barCodeData = (char*)mymalloc(SRAMIN,len);
for (int r = 0; r < my_symbol->rows; r++)
{
for (i = 0; i < my_symbol->width; i++)
{
barCodeData[r*(my_symbol->width + 1) + i] = module_is_set(my_symbol, r, i) ? '1' : '0';
}
barCodeData[r*(my_symbol->width + 1) + i] = ',';
}
ImageSize.x0 = 0;
ImageSize.y0 = 0;
if(Msg->GeneralPara4 == 0){
#if DEBUG
printf("Code error");
#endif
ImageSize.x1 = 120;
ImageSize.y1 = 30;
}
else if(Msg->GeneralPara4 == 1)
{
ImageSize.x1 = (my_symbol->width+1)*Msg->GeneralPara2;
ImageSize.y1 = Msg->GeneralPara1;
}
else
{
ImageSize.x1 = my_symbol->width*Msg->GeneralPara1;
ImageSize.y1 = Msg->GeneralPara2*my_symbol->rows*Msg->GeneralPara1;
if(ImageSize.y1 > 154)
ImageSize.y1 = 154;
}
ZBarcode_Delete(my_symbol);
hMem = GUI_MEMDEV_CreateFixed(0, 0, ImageSize.x1, ImageSize.y1, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_888);
GUI_MEMDEV_Select(hMem);
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
if(Msg->GeneralPara4 == 0)
{
GUI_SetFont(System24_Font);
GUI_SetTextMode(GUI_TM_TRANS);
GUI_SetColor(GUI_BLACK);
GUI_DispStringAt(tr("Code error"),2,2);
}
else if(Msg->GeneralPara4 == 1) //画条码
{
for(int i=0; i
{
if(barCodeData
== '1')
{
GUI_SetColor(GUI_BLACK);
}
else if(barCodeData == '0')
{
GUI_SetColor(GUI_WHITE);
}
x1 += Msg->GeneralPara2;
GUI_FillRect(x1, y1, x1 + Msg->GeneralPara2, y1 + Msg->GeneralPara1);
}
}
else //画二维码
{
for(int i=0; i
{
if(barCodeData == '1')
{
GUI_SetColor(GUI_BLACK);
}
else if(barCodeData == '0')
{
GUI_SetColor(GUI_WHITE);
}
if(barCodeData==',')
{
x1 = 0;
y1 += Msg->GeneralPara1* Msg->GeneralPara2;
}
else
{
GUI_FillRect(x1, y1, x1 + Msg->GeneralPara1, y1 + Msg->GeneralPara1* Msg->GeneralPara2);
x1 += Msg->GeneralPara1;
}
}
}
GUI_MEMDEV_Select(0);
myfree(SRAMIN,barCodeData);
Msg->XSize = ImageSize.x1;
Msg->YSize = ImageSize.y1;
return hMem;
}
这是绘制条码二维码的代码,更改或添加SWITCH中的条码类,即可添加所想要的条码类
static WM_HMEM GetBarcodeImage(DATAFORMAT *Msg)
{
GUI_RECT ImageSize;
struct zint_symbol* my_symbol = ZBarcode_Create();
int fd;
U32 len;
int i;
U16 x1=0,y1=0;
char *barCodeData;
WM_HMEM hMem;
switch(Msg->GeneralPara0)
{
case 0:
my_symbol->symbology = BARCODE_CODE128;
break;
case 1:
my_symbol->symbology = BARCODE_EANX;
break;
case 2:
my_symbol->symbology = BARCODE_QRCODE;
break;
}
fd = ZBarcode_Encode(my_symbol,Msg->DispProp,0);
Msg->GeneralPara4 = my_symbol->rows;
len = my_symbol->rows*(1 + my_symbol->width);
barCodeData = (char*)mymalloc(SRAMIN,len);
for (int r = 0; r < my_symbol->rows; r++)
{
for (i = 0; i < my_symbol->width; i++)
{
barCodeData[r*(my_symbol->width + 1) + i] = module_is_set(my_symbol, r, i) ? '1' : '0';
}
barCodeData[r*(my_symbol->width + 1) + i] = ',';
}
ImageSize.x0 = 0;
ImageSize.y0 = 0;
if(Msg->GeneralPara4 == 0){
#if DEBUG
printf("Code error");
#endif
ImageSize.x1 = 120;
ImageSize.y1 = 30;
}
else if(Msg->GeneralPara4 == 1)
{
ImageSize.x1 = (my_symbol->width+1)*Msg->GeneralPara2;
ImageSize.y1 = Msg->GeneralPara1;
}
else
{
ImageSize.x1 = my_symbol->width*Msg->GeneralPara1;
ImageSize.y1 = Msg->GeneralPara2*my_symbol->rows*Msg->GeneralPara1;
if(ImageSize.y1 > 154)
ImageSize.y1 = 154;
}
ZBarcode_Delete(my_symbol);
hMem = GUI_MEMDEV_CreateFixed(0, 0, ImageSize.x1, ImageSize.y1, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_888);
GUI_MEMDEV_Select(hMem);
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
if(Msg->GeneralPara4 == 0)
{
GUI_SetFont(System24_Font);
GUI_SetTextMode(GUI_TM_TRANS);
GUI_SetColor(GUI_BLACK);
GUI_DispStringAt(tr("Code error"),2,2);
}
else if(Msg->GeneralPara4 == 1) //画条码
{
for(int i=0; i
{
if(barCodeData == '1')
{
GUI_SetColor(GUI_BLACK);
}
else if(barCodeData == '0')
{
GUI_SetColor(GUI_WHITE);
}
x1 += Msg->GeneralPara2;
GUI_FillRect(x1, y1, x1 + Msg->GeneralPara2, y1 + Msg->GeneralPara1);
}
}
else //画二维码
{
for(int i=0; i
{
if(barCodeData == '1')
{
GUI_SetColor(GUI_BLACK);
}
else if(barCodeData == '0')
{
GUI_SetColor(GUI_WHITE);
}
if(barCodeData==',')
{
x1 = 0;
y1 += Msg->GeneralPara1* Msg->GeneralPara2;
}
else
{
GUI_FillRect(x1, y1, x1 + Msg->GeneralPara1, y1 + Msg->GeneralPara1* Msg->GeneralPara2);
x1 += Msg->GeneralPara1;
}
}
}
GUI_MEMDEV_Select(0);
myfree(SRAMIN,barCodeData);
Msg->XSize = ImageSize.x1;
Msg->YSize = ImageSize.y1;
return hMem;
}
这是绘制条码二维码的代码,更改或添加SWITCH中的条码类,即可添加所想要的条码类
举报