压力算法移植前
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
#include "QBarCode.h"
|
||||
#include "ui_myBarCode.h"
|
||||
#include "QImage"
|
||||
#include "QFile"
|
||||
#include "QFileInfo"
|
||||
#include "QDebug"
|
||||
#include "stdio.h"
|
||||
|
||||
QBarCode::QBarCode(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::QBarCode)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->BarCodeGenerate,SIGNAL(pressed()),this,SLOT(onEnCodeBar()));
|
||||
|
||||
ui->lineEdit->setText("12345678ABCDEFG");
|
||||
|
||||
//onEnCodeBar();
|
||||
|
||||
}
|
||||
|
||||
QBarCode::~QBarCode()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void QBarCode::onEnCodeBar(){
|
||||
|
||||
QFile f1;
|
||||
//ui->lineEdit->setText("dfdsfdsfdsfdsf");
|
||||
int ps = 1, pcl = 0, oflags;
|
||||
ps = 0; pcl = 0;
|
||||
|
||||
oflags = BARCODE_OUT_PS | BARCODE_OUT_NOHEADERS;
|
||||
|
||||
// char *txt = ui->lineEdit->text.toStdString().c_str();
|
||||
//sprintf(txt,"%s", (char *)ui->lineEdit->text().data());
|
||||
/* and my data as code-128B autodetected */
|
||||
QString txt =ui->lineEdit->text();
|
||||
Barcode_Encode_and_Print((char *)txt.toStdString().c_str(),stdout, 0, 60, 240, 510,
|
||||
oflags);
|
||||
|
||||
/* A few code-39 ones */
|
||||
// Barcode_Encode_and_Print("silly code",stdout, 0, 0, 40, 320,
|
||||
// BARCODE_39 | oflags);
|
||||
|
||||
// Barcode_Encode_and_Print("SAMPLE CODES",stdout, 100, 30, 400, 80,
|
||||
// BARCODE_39 | oflags);
|
||||
|
||||
/* ISBN with add-5 */
|
||||
// Barcode_Encode_and_Print("1-56592-292-1 90000",stdout, 0, 0, 40, 430,
|
||||
// BARCODE_ISBN | oflags);
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* Do it all in one step
|
||||
*/
|
||||
int QBarCode::Barcode_Encode_and_Print(char *text, FILE *f, int wid, int hei,
|
||||
int xoff, int yoff, int flags)
|
||||
{
|
||||
struct Barcode_Item * bc;
|
||||
|
||||
if (!(bc=Barcode_Create(text))) {
|
||||
qDebug()<<"mem less then:";//<< -ENOMEM ;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( Barcode_Position(bc, wid, hei, xoff, yoff, 0.0) < 0
|
||||
|| Barcode_Encode(bc, flags) < 0
|
||||
//|| Barcode_Print(bc, f, flags) < 0
|
||||
) {
|
||||
qDebug()<< bc->error;
|
||||
Barcode_Delete(bc);
|
||||
return -1;
|
||||
}
|
||||
//QFile f1;
|
||||
bcText = text;
|
||||
bcTextinfo = bc->textinfo;
|
||||
bcPartial = bc->partial;
|
||||
ui->textEdit->setText(bcPartial);
|
||||
|
||||
Barcode_ToImage(bc);
|
||||
|
||||
Barcode_Delete(bc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 将条形码编码转换成点阵图形
|
||||
int QBarCode::Barcode_ToImage(Barcode_Item * bc ){
|
||||
bc->ascii;
|
||||
bc->partial;
|
||||
bc->textinfo;
|
||||
int len =QString(bc->partial).length();
|
||||
bcWidth =6;
|
||||
for(int i=0;i<len;i++)
|
||||
bcWidth+= (bc->partial[i]&0x0f);
|
||||
//
|
||||
//bcWidth = len;
|
||||
bcHeight = 40;
|
||||
|
||||
QImage image(bcWidth,bcHeight,QImage::Format_ARGB32);
|
||||
//image.dotsPerMeterX()
|
||||
//image.size().setHeight(50);
|
||||
image.fill(0x00ffffff);
|
||||
//QPainter painter(&image);
|
||||
//ui->textEdit->document()->drawContents (&painter, image.rect()); /*将text写到pic*/
|
||||
QString txt = bc->ascii;
|
||||
|
||||
ui->textEdit->setText( QString().sprintf("W:%d,H:%d,Len:%d",ui->BarCodeView->width(),ui->BarCodeView->height(),len));
|
||||
|
||||
//0b1a2a4123221223211221132221231213212223112312131311222314111b3c1a1b
|
||||
//11:12:1 22:12:2 33:12:3 44:12:4 55:12:5 66:12:6 77:12:7 88:12:8
|
||||
//02112141232212232112211322212312132122231123121313112223141112331112
|
||||
|
||||
memset(pointMap,0,sizeof(pointMap));
|
||||
unsigned char *img= image.bits();
|
||||
for(int j=0;j< 20;j++){
|
||||
int i=3;
|
||||
unsigned char p=0;
|
||||
for(int n=0;( n<len);n++)
|
||||
{
|
||||
int c= bc->partial[n];
|
||||
if(c<0x30 || c>127) continue;
|
||||
c = c-0x30;
|
||||
if(n%2==1){
|
||||
for(int r=0;r<c;r++){
|
||||
*( img+j*bcWidth*4+i*4)= 0;
|
||||
*( img+j*bcWidth*4+i*4+1)= 0;
|
||||
*( img+j*bcWidth*4+i*4+2)= 0;
|
||||
*( img+j*bcWidth*4+i*4+3)= 0;
|
||||
i++;
|
||||
// p= (p<<1) | 0x01;
|
||||
// pointMap[j*bcWidth+i]=1;
|
||||
|
||||
}
|
||||
}
|
||||
else i+=c;
|
||||
}
|
||||
}
|
||||
|
||||
QString fileName="\\home\\plg\\doc\\"+ txt + ".BMP" ;
|
||||
|
||||
image.save(fileName);
|
||||
QFileInfo(fileName).fileName();
|
||||
// ui->labBarCode->setPixmap(QPixmap(QString::fromUtf8(".\\imgd.BMP")));
|
||||
|
||||
//ui->widgetPrintTextDisplay->dat = pointMap;
|
||||
|
||||
ShowBarCode(fileName);
|
||||
}
|
||||
|
||||
void QBarCode::ShowBarCode(QString fileName)
|
||||
{
|
||||
/****************界面初始化********************************/
|
||||
|
||||
this->pictureName =fileName ;
|
||||
scene = new QGraphicsScene;
|
||||
scene->setSceneRect( -200,0,bcWidth*4+200,bcHeight);
|
||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
QPixmap pixmap(this->pictureName);
|
||||
pixmap = pixmap.scaledToWidth(2.5*bcWidth);
|
||||
item = scene->addPixmap(pixmap);
|
||||
|
||||
/***************设置view的场景*****************************/
|
||||
ui->BarCodeView->setScene(scene);
|
||||
ui->BarCodeView->setRenderHint(QPainter::Antialiasing);
|
||||
ui->BarCodeView->setCacheMode(QGraphicsView::CacheBackground);
|
||||
ui->BarCodeView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
||||
ui->BarCodeView->setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
//ui->graphicsView->resize(400,300);
|
||||
|
||||
ui->BarCodeView->setScene(scene);//设置view的场景
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user