对文件进行加密
以二进制流 写入加密二进制串+Image = 新文件
解密时 读取同样长度的二进制+Image 即可解密
同时保存Image时要注意文件头问题,不能直接以二进制流写入!
不同格式的文件有着不同的文件头!
新文件,新思维
void MainWindow::on_pushButton_clicked()
{
QStringList files = QFileDialog::getOpenFileNames(this,QDir::currentPath(),"","Images (*.png *.bmp *.jpg)");
foreach (QString filename, files) {
qDebug()<<filename;
QImage pImage(filename);
QFile writefile(filename+".my");
writefile.open(QIODevice::WriteOnly);
QDataStream data(&writefile);
data << (quint32)0xA0B0C0D0<<pImage;
qDebug()<< writefile.size();
writefile.flush();
}
ui->label->setText("Encryption success");
}
//
void MainWindow::on_pushButton_2_clicked()
{
QStringList files = QFileDialog::getOpenFileNames(this,QDir::currentPath(),"","*.my");
foreach (QString filename, files) {
qDebug()<<filename;
QImage pImage;
quint32 n;
QFile readfile(filename);
readfile.open(QIODevice::ReadOnly);
QDataStream data(&readfile);
data>> n >>pImage;
pImage.save(filename+".jpg");
ui->label->setText("Decryption is runing ");
}
ui->label->setText("Decryption success");
}