현재 Qt로 스테 가노 그래피 응용 프로그램을 작성 중입니다. 픽셀의 파란색 색상의 최하위 비트에서 메시지 비트를 숨기려고합니다.Qt QImage 픽셀 조작 문제
디버깅에서 나는이 섹션이 제대로 작동하고 있음을 알 수 있습니다. 그러나 메시지에 내 비트를 숨기고 나서 이미지를 저장 한 다음 다시 엽니 다. 문제가 발생하는 곳입니다.
내가 (다시 열어 본) 이미지를 읽을 때 내가 읽은 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;
}
감사
손실 압축 형식을 사용하고 있지 않습니까? –