我将QT 5.7用于必须将QPixmap转换为base64 QString格式的程序。我试图先将QPixmap转换为cv :: Mat,然后添加我现有的转换流程。
$: x="
this
is
variably indented
stuff
"
$: echo "$x" # preserves the newlines and spacing
this
is
variably indented
stuff
$: echo $x # no quotes, stacks it "neatly" with minimal spacing
this is variably indented stuff
但是它返回错误:
Qpixmap pix;
cv::Mat pixData(pix.rows(),pix.cols(),CV_8UC3,pix.scanline());
std::vector<uchar> IMbuffer;
cv::imencode(".png", pixData, IMbuffer);
QByteArray byteArray = QByteArray::fromRawData((const char*)IMbuffer.data(), IMbuffer.size());
QString base64Image(byteArray.toBase64());
因此很明显,从QPixmap到cv :: Mat的这种转换是不兼容的。那么,有什么简单的方法可以将QPixmap转换为base64 QString?
答案 0 :(得分:0)
尝试一下;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
pix.save(&buffer, "PNG");
auto const encoded = buffer.data().toBase64();