C++图片隐写(在图像结束标志后加入数据)

jpg图像开始标志:FF D8 结束标志 :FF D9

#include  
#include 
using namespace std; 
class picture{
private:
	ifstream ifile_picture;
	ifstream ifile_txt;
	ofstream ofile_picture;
	ofstream ofile_txt;
	int length_ifile_picture,length_ifile_txt;
	char name_ifile_picture[50], name_ifile_txt[50], name_ofile_picture[50],name_ofile_txt[50];
public:
	void Open(ifstream &ifile,char *name,int &length);
	void M();
	void m();
}; 
void picture::Open(ifstream &ifile,char *name,int &length)   
{
	ifile.open(name,ios::binary|ios::in);
	if (!ifile)
	{
		cout<<"Open "<>this->name_ifile_picture;
	Open(this->ifile_picture , this->name_ifile_picture , this->length_ifile_picture);
	str = new char[length_ifile_picture + 5];
	this->ifile_picture.read(str , this->length_ifile_picture);
	while(1)
	{
		if(str[this->length_ifile_picture-2]==-1  && str[this->length_ifile_picture-1]==-39)break;   //图像结束标志  FF D9
		else this->length_ifile_picture--;
	}
	cout<<"请输入修改后的图片名(需要加后缀名):"<>this->name_ofile_picture; 
	this->ofile_picture.open(this->name_ofile_picture,ios::binary|ios::out);
	if (!this->ofile_picture)
	{
		cout<<"Open "<name_ofile_picture<<" failed!"<ofile_picture.write(str , this->length_ifile_picture); 
	this->ifile_picture.close();
	delete []str;
	cout<<"请输入文本名(需要加后缀名):"<>this->name_ifile_txt;	
	Open(this->ifile_txt , this->name_ifile_txt , this->length_ifile_txt);
	str = new char[length_ifile_txt + 5];
	this->ifile_txt.read(str , this->length_ifile_txt);
	this->ofile_picture.write(str , this->length_ifile_txt);
	this->ifile_txt.close();
	this->ofile_picture.close();
	delete []str;	
	cout<<"成功!"<>this->name_ifile_picture;
	Open(this->ifile_picture , this->name_ifile_picture , this->length_ifile_picture);
	str = new char[length_ifile_picture + 5];
	this->ifile_picture.read(str , this->length_ifile_picture);
	int l=this->length_ifile_picture;
	while(1)
	{
		if(str[l-2]==-1   && str[l-1] == -39)break;   //图像结束标志  FF D9
		else l--;
	}
	cout<<"请输入信息提取存入文本名(需要加后缀名):"<>this->name_ofile_txt; 
	this->ofile_txt.open(this->name_ofile_txt,ios::binary|ios::out);
	if (!this->ofile_picture)
	{
		cout<<"Open "<name_ofile_txt<<" failed!"<ofile_txt.write(str+l , this->length_ifile_picture-l);
	this->ifile_picture.close();
	this->ofile_txt.close();
	delete []str;
	cout<<"成功!"<

你可能感兴趣的:(图片隐写)