#include "stdafx.h" #include "binconbmp.h" using namespace std; bool binconbmp(char* binname,int width,int height) { bool result=false; unsigned char* ds=(unsigned char*)malloc(sizeof(unsigned char)*width*height); if(!ds) { write_to_log("BinConBMP: out of memory for ds."); return result; } ifstream fin(binname,ios::in); if(!fin.is_open()) { char log_txt[512]; sprintf(log_txt, "BinConBMP: Could not open file %s.", binname); write_to_log(log_txt); return result; } for(int aa=0;aa<width*height;aa++) { fin.clear(); fin.seekg(aa); unsigned char value; fin >> value;//fin.read(&value,1); ds[aa]=value; } fin.close(); int* color=(int*)malloc(sizeof(int)*width*height); if(!color) { write_to_log("BinConBMP: out of memory for color."); return result; } for(int j=1;j<=height;j++) { for(int i=1;i<=width;i++) { int x,y,id; x=i; y=height-j; id=y*width+x-1; color[id]=(unsigned char)ds[(j-1)*width+x-1]; } } if(ds!=NULL) free(ds); char bmpname[512]; sprintf(bmpname,"%s.bmp",binname); bmp_write(bmpname,width,height,color,color,color); if(color!=NULL) free(color); result=true; return result; }