[英]Qt QImage pixel manipulation problems
I'm currently in the process of writing a steganography application with Qt. 我目前正在用Qt编写一个隐写术应用程序。 I am trying to hide my message bits in the least significant bit of the blue colour of the pixel. 我试图隐藏在像素的蓝色的最低有效位中的消息位。
From debugging I can tell that this section is working as it should. 从调试我可以看出这部分正常工作。 However after hiding my bits in the message I then save the image and then reopen it. 然而,在将我的位隐藏在消息中后,我保存图像然后重新打开它。 This is where the problem develops. 这是问题发展的地方。
When I read in the (reopened) image the scanLines
that I read in are not the same as the ones I wrote previously, and I can't figure out why. 当我读入(重新打开)的图像时,我读入的scanLines
与我之前写的那些不同,我无法弄清楚原因。 Maybe it's just me being stupid, or maybe I'm missing something. 也许这只是我的愚蠢,或者我可能错过了一些东西。 Any help would be much appreciated. 任何帮助将非常感激。
The code I have so far is as follows 我到目前为止的代码如下
void MainWindow::Encrypt(QImage image, QString message) {
if(image.isNull()) {
qDebug() << "PROBLEM";
}
image = image.convertToFormat(QImage::Format_ARGB32);
QVector<bool> bvec;
QByteArray bytes = message.toAscii();
char mask;
QRgb tempPix;
for(int i = 0; i < bytes.size(); i++) {
for(int j = 0; j < 8; j++) {
mask = (0x01 << j);
bvec.push_back((bytes[i] & mask) == mask);
}
}
if(image.height() < bvec.size()) {
qDebug() << "Not enough space in image";
}
for(int j = 0; j < bvec.size(); j++) {
QRgb *pixel = (QRgb *)image.scanLine(j);
tempPix = *pixel;
int blue = qBlue(tempPix);
blue &= 0xFE;
blue |= (bvec[j] == 1) ? 0x01 : 0x00;
*pixel = qRgba(qRed(tempPix), qGreen(tempPix), blue, qAlpha(tempPix));
}
if(image.save(filename) != true) {
emit addToStatusLog("Did not save. Error");
}
}
void MainWindow::Decrypt(QImage image) {
char temp = 0x00;
qint8 mask = 0x01;
QVector<bool> bvec;
QRgb *pixel;
int blue;
image = image.convertToFormat(QImage::Format_ARGB32);
for(int i = 0; i < image.height(); i++) {
pixel = (QRgb *)image.scanLine(i);
blue = qBlue(*pixel);
bvec.push_back((blue & mask) == mask);
}
for(int j = 0; j < bvec.size(); j++) {
if(j % 8 == 0 && j != 0) {
qDebug() << temp;
temp = 0x00;
}
temp |= (bvec[j]) ? (0x01 << (j%8)) : 0x00;
}
qDebug() << temp;
}
Thanks 谢谢
确保您没有使用有损格式保存,例如JPEG。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.