【问题标题】:Qt QImage pixel manipulation problemsQt QImage 像素操作问题
【发布时间】:2010-10-25 20:53:34
【问题描述】:

我目前正在使用 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;
}

谢谢

【问题讨论】:

  • 你没有使用有损压缩格式吗?

标签: c++ qt bit-manipulation steganography qimage


【解决方案1】:

确保您没有使用有损格式(例如 JPEG)进行保存。

【讨论】:

  • 非常感谢,将其保存为 PNG 可以解决问题。 =]
猜你喜欢
  • 2011-04-05
  • 2016-07-05
  • 1970-01-01
  • 2012-02-26
  • 1970-01-01
  • 1970-01-01
  • 2012-11-14
  • 2018-06-22
  • 1970-01-01
相关资源
最近更新 更多