简体   繁体   English

读取bmp文件数据并将其写入另一个bmp

[英]Read a bmp file data and write it to another bmp

I have written a code where I tried to read a bmp file and write it to another file.When I try to write it an output file creates but it does not open . 我已经编写了一个代码,试图读取bmp文件并将其写入另一个文件。当我尝试将其写入时,会创建一个输出文件,但无法打开。 here is my code 这是我的代码

#include<iostream>
#include<fstream>

using namespace std;
//int writeFile(string content);
int main() {

ifstream myReadFile;
ofstream myWriteFile;
 myReadFile.open("D:/MIT_Database/barbara_gray.bmp");
 myWriteFile.open("D:/MIT_Database/barbara_graywrite.bmp");
  char output[100];
 string content;
 if (myReadFile.is_open()) {
 while (!myReadFile.eof()) {
getline( myReadFile, content );
 cout<<content;
 // myReadFile >> output;
   for(int i=0;i<content.length();i++)
{myWriteFile<<content[i];}
 //  myWriteFile<<content<<'\n';
  myWriteFile<<'\n';
  }

}

 myReadFile.close();
 myWriteFile.close();
 return 0;

} }

here is my file 这是我的档案 在此处输入图片说明

fstream in("test.bmp",ios::binary|ios::in); fstream in(“ test.bmp”,ios :: binary | ios :: in);

fstream out("new.bmp",ios::binary|ios::out); fstream out(“ new.bmp”,ios :: binary | ios :: out);

char c; 字符c;

while(!in.eof()) { while(!in.eof()){

c=in.get(); C = in.get();

out.put(c); out.put(C); } }

in.close(); 附寄();

out.close(); out.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM