131 lines
2.5 KiB
C++
131 lines
2.5 KiB
C++
#include "creatprintbmp.h"
|
|
|
|
CreatPrintBmp::CreatPrintBmp(QObject *parent) : QObject(parent)
|
|
{
|
|
m_savePath.clear();
|
|
m_mcIdx = 0;
|
|
}
|
|
|
|
CreatPrintBmp::~CreatPrintBmp()
|
|
{
|
|
|
|
}
|
|
|
|
void CreatPrintBmp::slotCreatBmp()
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
QPen pen;
|
|
pen.setWidth(1);
|
|
pen.setColor(QColor(Qt::black));
|
|
|
|
//将picture保存为多个宽度为2400像素的bmp
|
|
int num = m_picture.width() / PIXMAPWIDTH;
|
|
int lwidth = m_picture.width() % PIXMAPWIDTH;
|
|
int height = m_picture.height();
|
|
int offset = 0;
|
|
|
|
if(lwidth != 0)
|
|
{
|
|
num += 1;
|
|
}
|
|
|
|
QBitmap *pixmap = new QBitmap(PIXMAPWIDTH,height);
|
|
QPainter *pixPainter = new QPainter();
|
|
pixPainter->setPen(pen);
|
|
pixPainter->begin(pixmap);
|
|
|
|
for(int i = 0 ; i < num; i++)
|
|
{
|
|
pixmap->fill(Qt::white);//用白色填充
|
|
pixPainter->drawPicture(offset,0,m_picture);
|
|
offset -= PIXMAPWIDTH;
|
|
|
|
QString path = m_savePath+QString::number(i+1)+".bmp";
|
|
bool bls = pixmap->save(path);
|
|
while(bls == false)
|
|
{
|
|
bls = pixmap->save(path);
|
|
qDebug()<<"pixmap save failed";
|
|
}
|
|
|
|
//压缩位图
|
|
BWBmp bwBmp;
|
|
int rslt;
|
|
|
|
rslt = bwBmp.LoadBiBmp(path);
|
|
if (rslt != 0)
|
|
{
|
|
qDebug() << "open file error" << path;
|
|
break;
|
|
}
|
|
rslt = bwBmp.Compress();
|
|
if (rslt != 0)
|
|
{
|
|
qDebug() << "Compress error";
|
|
break;
|
|
}
|
|
|
|
rslt = bwBmp.SavePrBmp(path+".prbmp");
|
|
if (rslt != 0)
|
|
{
|
|
qDebug() << "save prbmp error";
|
|
break;
|
|
}
|
|
QByteArray dat = bwBmp.getPrBmpDat();
|
|
siCreatOneBmpFinished(m_mcIdx,(u8*)dat.data(),dat.size());
|
|
}
|
|
|
|
pixPainter->end();
|
|
|
|
bool bla = pixPainter->isActive();
|
|
while(bla == true)
|
|
{
|
|
bla = pixPainter->isActive();
|
|
qDebug()<<"pixPainter isActive";
|
|
}
|
|
|
|
delete pixmap;
|
|
delete pixPainter;
|
|
}
|
|
|
|
void CreatPrintBmp::setPicture(QPicture pic)
|
|
{
|
|
m_picture = pic;
|
|
}
|
|
|
|
void CreatPrintBmp::setPicture(QBitmap bitmap)
|
|
{
|
|
//将图片画在picture上
|
|
QPicture pic;
|
|
QPen pen;
|
|
pen.setWidth(1);//设置笔号
|
|
pen.setColor(QColor(Qt::black));
|
|
|
|
QPainter painter;
|
|
painter.begin(&pic);
|
|
painter.setPen(pen);
|
|
painter.drawPixmap(0,0,bitmap);
|
|
painter.end();
|
|
m_picture = pic;
|
|
}
|
|
|
|
void CreatPrintBmp::setSavePath(QString path)
|
|
{
|
|
m_savePath.clear();
|
|
m_savePath = path;
|
|
}
|
|
|
|
void CreatPrintBmp::setMcIdx(int idx)
|
|
{
|
|
m_mcIdx = idx;
|
|
}
|
|
|
|
QString CreatPrintBmp::getSavePath()
|
|
{
|
|
return m_savePath;
|
|
}
|