记录一下,以备以后查阅
QImage image;
image.load("/home/edge/workspace/script/test0.tiff"); //从路径加载图片
image.format(); //查看图片格式
int bytesPerLine = image.bytesPerLine();
int height = image.height();
uchar* imageData = image.bits();
QByteArray byteArray((char*)imageData, bytesPerLine * height); //将QImage转换为QByteArray
//构建添加数据
QByteArray append_data;
append_data.resize(bytesPerLine);
append_data.fill(0); //全部写0
append_data.replace(0,5,"hello"); //替换想要添加的内容
byteArray.append(append_data);
//QByteArray转QImage
QImage all_image((uchar*)byteArray.data(),8000,6001,QImage::Format_Grayscale16);
bool temp = all_image.save("/home/edge/workspace/script/test1.tiff"); //将添加数据后的图片保存
qDebug() << temp;
//读取添加后的图像数据
unsigned char *image_data = all_image.scanLine(6032); //返回当前行数指针
QByteArray out_data((char*)image_data,-1);
qDebug() << out_data; //输出