Qt的QImage的像素处理问题
-
21-08-2019 - |
题
我目前在写使用Qt一个隐写应用程序的过程。我试图隐藏我的消息比特像素的蓝色的最低显著位。
从调试,我可以告诉大家,这部分工作,因为它应该。躲在我的位消息后,但是我然后保存图像,然后重新打开它。这就是问题的发展。
当我在(重新)图像读取予读入是不一样的,因为我以前写过的那些的scanLines
,我不能找出原因。也许这只是我太傻了,也许我失去了一些东西。任何帮助,将不胜感激。
我到目前为止的代码如下
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;
}
由于
解决方案
请确保您使用的不是有损格式,如JPEG保存。
不隶属于 StackOverflow